简体   繁体   English

当图像已上传到文件夹中时,如何解决 laravel 中的“文件不存在或不可读”

[英]how to solve “file does not exist or is not readable” in laravel while the image have been uploaded in folder

在此处输入图像描述

I am getting this error while trying to upload a file, but the file is being uploaded cause I can find it in the directory, but instead of proceeding, it throws this error, and I have been using this script for long until laravel 6.0 and I don't get the reasons why!我在尝试上传文件时收到此错误,但正在上传文件,因为我可以在目录中找到它,但它没有继续,而是抛出此错误,我一直在使用此脚本,直到laravel 6.0和我不明白为什么! thanks谢谢

$image_name=Str::random(12);
$ext=strtolower($image->getClientOriginalExtension());
$image_full_name=$image_name.'.'.$ext;
$upload_path='upload/article/';
$image_url=$upload_path.$image_full_name;
// $success=1;
$success=$image->move($upload_path,$image_full_name);
// return $success;
if($success)
{
    $data['post_photo']=$image_url;
    DB::table('post')->insert($data);
    Session::put('message','article posted Successfully');
    return Redirect::to('create-post');
}

here is my Html code这是我的 Html 代码

<div class="custom-file">
   <input type="file" class="custom-file-input form-control  " id="customFileLang" name="photo" >
   <label class="custom-file-label" for="customFileLang">Choose Picture </label>
</div>
@error("photo")
  <p style="color:red;" class="mx-4">{{ $message }}</p>
@enderror

                  ```

Сheck that the call $validator->fails() occurs once.检查调用$validator->fails()发生一次。

In my case, the first call $validator->fails() in my Controller action, after checking deleted the file.就我而言,在检查删除文件后,在我的 Controller 操作中第一次调用$validator->fails() The second call could not find this file.第二次调用找不到这个文件。

If the file is successfully uploaded, so the problem is somewhere else, but unfortunately this error representing is so confusing and is not the actual error.如果文件上传成功,那么问题就出在其他地方,但不幸的是,这个错误表示的太混乱了,并不是真正的错误。
The actual error is happening where you're inserting data into database, in your case is this line:实际错误发生在您将数据插入数据库的地方,在您的情况下是这一行:

DB::table('post')->insert($data); // the case in this question

and in my case was a line I was trying to insert a blog to database:在我的情况下,我试图将博客插入数据库:

Blog::create($data); // my case

In order to find out what is the real error you have to use try and catch.为了找出真正的错误,您必须使用 try 和 catch。

try {
  DB::table('post')->insert($data); // for my case : Blog::create($data);
} catch (\Exception $e) {
  dd($e);
}

when you dump and die $e , you will see the actual error:当您转储并死掉$e时,您将看到实际错误:

在此处输入图像描述

for me, In my case the actual error was: " Field 'author_type' doesn't have a default value ", but for some unknown reasons laravel 6.0 shows " file does not exists or is not readable error " when you have uploaded data within your form.对我来说,在我的情况下,实际错误是:“字段'author_type'没有默认值”,但由于某些未知原因,laravel 6.0 显示“文件不存在或不可读错误”当您在其中上传数据时你的表格。

If someone else hits this error, try checking your php.ini...make sure that your upload_max_filesize is as big as your post_max_size.如果其他人遇到此错误,请尝试检查您的 php.ini...确保您的 upload_max_filesize 与您的 post_max_size 一样大。 I had 1000M for post_max_size, but only 100M for upload_max_size.我有 1000M 用于 post_max_size,但只有 100M 用于 upload_max_size。 The upload would churn for a long time, and then throw the error above (except it had "" as the file name, and no file was uploaded).上传会搅动很长时间,然后抛出上面的错误(除了它有“”作为文件名,并且没有上传文件)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 laravel 文件不存在或不可读 - laravel file does not exist or is not readable laravel 文件上传 - &quot;&quot; 文件不存在或不可读 - laravel file upload - The "" file does not exist or is not readable 无法上传 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 throws an error “file does not exist or is not readable.” 如何解决此 Laravel 问题 - “/tmp/phpY14gRo”文件不存在或不可读? - How to resolve this Laravel issue - The “/tmp/phpY14gRo” file does not exist or is not readable? 我上传了2张图片文件,但只有一个保存在文件夹中 - i have 2 image file uploaded but only one save on folder php上传的文件不存在 - php uploaded file does not exist $ _FILES包含上传的文件,而Laravel请求则不包含 - $_FILES contains the uploaded file while Laravel request does not &quot;message&quot;: &quot;关键路径 \\&quot;file:///app/storage/oauth-private.key\\&quot; 在 Laravel 6 中不存在或不可读&quot; - "message": "Key path \"file:///app/storage/oauth-private.key\" does not exist or is not readable" in Laravel 6 Laravel:上传文件时如何在公共路径中动态创建文件夹? - Laravel: How to create a folder in public path dynamically when a file is uploaded?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM