【发布时间】:2017-05-16 09:36:19
【问题描述】:
我想将我的图像存储到特定文件夹,该文件夹将由页面 ID 命名。例如,如果 Page id=1,则文件夹位置应为 public/pages/page_id/image_here。
如果文件夹尚不存在,系统将生成并使用其页面 id 命名。
$id=1;
$directoryPath=public_path('pages/' . $id);
if(File::isDirectory($directoryPath)){
//Perform storing
} else {
Storage::makeDirectory($directoryPath);
//Perform storing
}
但是我遇到了“mkdir(): Invalid argument”的错误。 我能知道为什么会这样吗?
经过我的研究,有人说文件夹名称应该以 id+token 为基础,所以入侵者无法根据 id 搜索图像,有没有可能实现?
【问题讨论】:
-
在你的 else 条件下,只需使用 File::makeDirectory instande of Storage::makeDirectory