[英]laravel file upload throws an error “file does not exist or is not readable.”
I'm trying to upload an image to images
folder.我正在尝试将图像上传到
images
文件夹。
if ($request->hasFile('pic')) {
$file = $request->file('pic');
$file_name = time() . '.' . $file->getClientOriginalExtension();
$destinationPath = public_path('/images/');
$file->move($destinationPath, $file_name);
$model->pic= $file_name;
}
But i get this error:但我得到这个错误:
The "./././php4E16.tmp" file does not exist or is not readable.
“./././php4E16.tmp”文件不存在或不可读。
I'm uploading a photo for a post in other controller with same code and its working fine.我正在为其他 controller 的帖子上传一张照片,使用相同的代码并且工作正常。
I can't figure out what's wrong.我不知道出了什么问题。
I'm not trying to upload large size images or somthing.我不是想上传大尺寸的图片或其他东西。
although the php.ini is edited to accept large files.尽管 php.ini 被编辑以接受大文件。
what I have tried:我尝试过的:
cache
.cache
。config cache
.config cache
。6.3
to 6.4
.6.3
更新到6.4
。enctype="multipart/form-data"
to form.enctype="multipart/form-data"
添加到表单中。 nothing works:\没有任何效果:\
I'm not sure whats happening here but the first time i tried to upload it worked but now its not working !我不确定这里发生了什么,但我第一次尝试上传它工作但现在它不工作!
Any idea what's wrong here?知道这里有什么问题吗?
Assuming you want to have these files in the public folder (ie, accessible to all), first do假设您希望将这些文件放在公用文件夹中(即所有人都可以访问),首先执行
php artisan storage:link
Then try something like this:然后尝试这样的事情:
if ($filesFromRequest = $request->file('files')) {
foreach ($files as $file) {
$storedFilePath = $file->store('public/some_files');
// Your Model Logic Here
}
}
If you need a full link to the file for the frontend, do:如果您需要前端文件的完整链接,请执行以下操作:
echo asset('storage/some_files/file.txt');
the issue was in the insert query..问题出在插入查询中..
a column was not given a value.没有给列一个值。
I managed to see the error by installing laravel package laravel-debugar
我通过安装 laravel package
laravel-debugar
设法看到了错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.