Laravel-我在服务器中上传文件时出现错误服务器错误

时间:2018-09-27 23:44:01

标签: laravel

我在我的Localhost中正确上传了文件,但是当我在服务器中上传应用程序时,他们给了我错误:上传文件后出现服务器错误。

这是我的控制器:

$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;

在我的本地主机中,文件保存在公用文件夹中。我想将文件保存在我的服务中public_html或public_html / image中。

1 个答案:

答案 0 :(得分:0)

$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);