首页 > 解决方案 > 使用 Laravel 在特定文件夹中创建目录

问题描述

我目前正在研究 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.

标签: phphtmllaravel-5.2storagecreate-directory

解决方案


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

根据文档,您可以这样做:请参阅此处

存储::makeDirectory($directory);

$directory您要创建的目录的路径在哪里,例如:

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

推荐阅读