【问题标题】:Create directory in specific folder using Laravel使用 Laravel 在特定文件夹中创建目录
【发布时间】:2018-11-24 11:31:59
【问题描述】:

我目前正在研究 Laravel,我创建了一个符号链接,将公共目录连接到存储使用:

php artisan storage:link

在目录中,我有另一个名为user_uploads 的文件夹,用于保存用户上传的文件。我有一个如下所示的输入字段:

<input type="file" name="image[]" id="imgInp" accept="image/jpeg, image/png, image/bmp, image/svg" multiple="multiple">

我验证文件,然后我要做的是:

 $image = $request->image;
    if($image){
        foreach($image as $image){
            $image = (array) $image; //convert the object to array
            // Now, I need to create the directory here and save the image(s) there
           // And, I have to name the folder the id of the row (row means the row of the database where the entry is saved). 
        }
    }else{
        return "No image selected";
    }

那么,我该怎么做呢?顺便说一句,我想要的文件夹是:

myProject/public/storage/user_uploads.

【问题讨论】:

    标签: php html laravel-5.2 storage create-directory


    【解决方案1】:

    你的问题不是很清楚,如果你参考了文档,那么实现起来并不难。

    根据文档,您可以这样做:refer here

    存储::makeDirectory($directory);

    其中$directory 是您要创建的目录的路径,例如:

    Storage::makeDirectory("myProject/public/storage/user_uploads/directory_you_want_to_create");
    

    【讨论】:

    • 我在发布问题之前尝试过,但它不起作用!
    • 请更新您的问题以反映这一点,并添加您遇到的错误。