Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freeccboy's avatar

problem when uploading an image in shared hosting file_put_contents

problem when uploading an image in shared hosting file_put_contents

It works normal on my local server, I already put write permissions to the folder where the images are saved

controller

$exploded=explode(',', $request->imagen); $decoded=base64_decode($exploded[1]);//here is de file ready $exploded=explode('/',$exploded[0]); $exploded=explode(';',$exploded[1]); $extension=$exploded[0]; $fileName=str_random().'.'.$extension; $path=public_path().'/images/'.$fileName; \Log::info($path); file_put_contents($path, $decoded);

Error

[2018-06-11 18:31:51] local.ERROR: file_put_contents(/home/u91#####/laravel/public/images/LA0NKmLC5aB1pMEE.png): failed to open stream: No such file or directory {"userId":1,"email":"[email protected]","exception":"[object] (ErrorException(code: 0): file_put_contents(/home/u91#####/laravel/public/images/LA0NKmLC5aB1pMEE.png): failed to open stream: No such file or directory at /home/u915923105/laravel/app/Http/Controllers/ArticuloController.php:125) [stacktrace] #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/home/u91592310...', 125, Array) #1 /home/u915923105/laravel/app/Http/Controllers/ArticuloController.php(125): file_put_contents('/home/u91592310...', '\x89PNG\

help me please

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

do you have an images folder ?

Note that it must be an exact match, ie, not Images for instance

1 like
freeccboy's avatar

thanks to your comment I just realized that the address that is saving the file is not in the public folder, thank you very much

freeccboy's avatar

/home/u91#####/laravel/public/images/ the correct routr /home/u91#####/public_html/images/

Please or to participate in this conversation.