【问题标题】:Laravel - Error Server Error when i upload File in ServerLaravel - 当我在服务器中上传文件时出现错误服务器错误
【发布时间】:2018-09-27 23:44:00
【问题描述】:

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

这是我的控制器:

$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 中。

【问题讨论】:

  • 错误是什么?
  • 我的帖子功能出错:“消息”:“服务器错误”
  • 这很有帮助..您更改了storage 文件夹的权限吗?
  • 不,先生,因为我在服务器上上传了我的应用程序,我没有更改路径或权限
  • 那么你的 public_html/ 权限是什么

标签: laravel


【解决方案1】:
$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);

【讨论】:

    猜你喜欢
    • 2014-12-11
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2016-11-13
    • 2017-01-16
    相关资源
    最近更新 更多