-1
When trying to upload an image with Laravel I notice a different code behavior depending on the size of the image preventing the upload of the file as demonstrated in the image below that I get with the function dd() in Laravel;
Code of my function to update the record with the image name to make the link in html;
public function update(Request $request, User $user, $id)
{
try {
DB::beginTransaction();
$data = $request->all();
$resource = $user->findOrFail((int)$id);
$img = $request->file('image');
if ($img) {
if ($img->isValid()) {
$nameFile = hash('md5', now()->timestamp) . '.' . $img->extension();
$upload = $request->file('image')->storeAs(
'marca', "$nameFile"
);
if (!$upload) {
throw new Exception('Falha ao enviar imagem!', '500');
}
$data['image'] = $nameFile;
} else {
dd(
$img,
$img->isValid(),
$img->getClientMimeType()
);
}
}
$resource->update($data);
DB::commit();
} catch (Exception $exception) {
DB::rollBack();
return redirect()->back()->withErrors($exception->getMessage());
}
return redirect("/user/$resource->id")->with('saved', "success");
}
But if I open the same image in Paint and reduce the size in percentage of the image to 25% I can upload the file normally.
Could someone tell why the code behaves differently in relation to the image size?
This is a server problem, not the Laravel problem, the Laravel site has an api for you to manage the strings by the get method.
– Macedo_Montalvão