php - 使用 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
.
解决方案
您的问题不清楚,如果您参考了文档,那么实现起来并不难。
根据文档,您可以这样做:请参阅此处
存储::makeDirectory($directory);
$directory
您要创建的目录的路径在哪里,例如:
Storage::makeDirectory("myProject/public/storage/user_uploads/directory_you_want_to_create");
推荐阅读
- php - 将数据发布到外部 URL
- r - 数据 [[grp[i]]] 中的错误:下标超出范围
- python - flask_sqlalchemy 使用字符串的哈希作为主键
- firebase - 在 Firestore 文档中实现细粒度数据验证
- excel - 我无法将 excel 文件导入 Microsoft 访问
- javascript - 框架 0.8.2 中的 EventListener 不起作用
- swift - NSButton 状态管理
- ruby-on-rails - 如何将 SimpleForm 输入配置为默认为无包装器
- android - 如何配置 gradle 以从资产目录中删除未使用的字体?
- php - 使用php代码“DELETE”,我怎样才能只为那一天保存一个不超过那一天的一个?