0
votes

I upload correctly my file in my Localhost, but when I upload my app in the server, they give me Error: Server Error after uploading the file.

This is my controller :

$exploded = explode(',', $request->image);
$decoded = base64_decode($exploded[1]);

if(str_contains($exploded[0], 'jpeg'))
  $extension = "jpg";
else
  $extension = "png";

$fileName = str_random().'.'.$extension;
$path = public_path().'/'.$fileName;
file_put_contents($path, $decoded);
$person->photo = $fileName;

In my localhost, files are saved in the public folder. I would like to save my files in my serve in public_html or in public_html/image.

1
whats the error?Seva Kalashnikov
Error on my post function : "message": "Server Error"yassine j
thats very helpful.. have you changed permissions for storage folder?Seva Kalashnikov
No Sir since i uploaded my app in server, i didnt change path or permissionsyassine j
So what's your public_html/ permissionTsaiKoga

1 Answers

0
votes
$file = $r->file('photo'); //get photo from output
$foreign_name = mt_rand(100000,999999);//name is betwwen 100000 and 999999
$destination = '/images'; //destination path
 $file_name = str_replace(' ', '_', $foreign_name);
 $file_name .= '.'.$file->getClientOriginalExtension(); //add to name jpg or png or...
 $file->move($destination, file_name);