简体   繁体   English

laravel 文件上传会引发错误“文件不存在或不可读”。

[英]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:我尝试过的:

  1. clearing the cache .清除cache
  2. clearing the config cache .清除config cache
  3. updated Laravel version from 6.3 to 6.4 .将 Laravel 版本从6.3更新到6.4
  4. added 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.

相关问题 无法上传 Laravel 中的图像:““C:\xampp\tmp\php38A9.tmp“文件不存在或不可读。” - Unable to upload image in Laravel: “The ”C:\xampp\tmp\php38A9.tmp“ file does not exist or is not readable.” laravel 文件上传 - "" 文件不存在或不可读 - laravel file upload - The "" file does not exist or is not readable laravel 文件不存在或不可读 - laravel file does not exist or is not readable 抛出新的FileException('文件必须可读。'); - throw new FileException('File must be readable.'); Laravel 文件不存在 - 文件上传 - Laravel file does not exist - file upload 安装Braintree并收到错误“Uncaught InvalidArgumentException:Dotenv:Environment file .env not found or not readable。” - Installing Braintree and getting error “Uncaught InvalidArgumentException: Dotenv: Environment file .env not found or not readable.” LocalSettings.php不可读。 正确的文件权限,然后重试 - LocalSettings.php not readable. correct file permissions and try again Laravel 5 文件上传 getClientOriginalExtention 不存在错误 - Laravel 5 File Uploading getClientOriginalExtention does not exist error Laravel 7.28“文件不存在错误 - Laravel 7.28 "the file does not exist error 文件“{$path}”不存在错误 laravel - File `{$path}` does not exist error In laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM