我想将我的图像存储到特定的文件夹,并且该文件夹将按页面ID命名。例如,如果Page id = 1,文件夹位置应该是public/pages/page_id/image_here。检查文件夹已经存在,如果没有在laravel中通过id创建一个新文件夹
如果该文件夹不存在,系统将生成并用其页面标识进行命名。
$id=1;
$directoryPath=public_path('pages/' . $id);
if(File::isDirectory($directoryPath)){
//Perform storing
} else {
Storage::makeDirectory($directoryPath);
//Perform storing
}
但我有错误,“mkdir():无效的参数”。 我可以知道它为什么会发生?
经过我的研究,有人说文件夹名称应该以id + token为基础,所以入侵者不能搜索基于id的图片,有没有可能实现?
只是用文件: :makeDirectory存储:: makeDirectory的实例 –
可能重复[在laravel中创建文件夹](http://stackoverflow.com/questions/21869223/create-folder-in-laravel) –