problem:
'image_logos' => 'pro4.jpeg',
if($request->hasfile('image_logos'))
{
log::info("elsehasfile path hai");
$file= $request->file('image_logos');
log::info($file);
$name = $file->getClientOriginalName();
log::info($name);
$publicPath = public_path();
log::info("public path hai");
log::info($publicPath);
$file->move(public_path().'/storage/item/', $name);
}
but it will not work
requirement
I need in this format
'image_logo' =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'Screenshot 2023-04-07 060417.png',
'mimeType' => 'image/png',
'error' => 0,
'hashName' => NULL,
)),
)
Solution
use this in form
enctype="multipart/form-data"
<form method="POST" action="{{ route('admin.item-broker.update') }}" enctype="multipart/form-data" class="">
If you're encountering an "image source not readable" error in a Laravel controller, it typically indicates an issue with reading the uploaded image file. There could be several reasons for this error, such as incorrect file permissions or a problem with the file upload itself. Here are a few troubleshooting steps you can follow:
Verify File Upload:
Ensure that the form has the enctype="multipart/form-data" attribute.
Confirm that the file input field has the name attribute set correctly (e.g., name="image").
Check File Permissions:
Ensure that the directory where you are trying to move the image has appropriate write permissions for the web server.
The directory should have write permissions (755 or 777) so that Laravel can move the uploaded file to that location.
You can use the following command in your terminal to adjust the permissions recursively: chmod -R 755 /path/to/directory.
Validate Uploaded File:
Make sure you're using the appropriate validation rules to validate the uploaded file in your controller.
Check if the required|image validation rules are applied to the file upload field.
Additionally, verify that the uploaded file is within the allowed file types (e.g., mimes:jpeg,png,jpg,gif).
You can temporarily remove the validation rules to see if the image is readable without validation.
Verify File Path:
Double-check that the path you are using to store the uploaded image is correct.
Use the public_path() helper function to get the absolute path to the public directory.
Ensure that you are appending the correct subdirectory or filename when constructing the image path.
Check File Size:
Confirm that the uploaded image file size is within the maximum allowed size (max:2048 in this example).
If the image size exceeds the limit, it may cause issues when trying to read or move the file.
Top comments (0)