【问题标题】:PHP File upload to NGINX & PHP5-FPMPHP 文件上传到 NGINX & PHP5-FPM
【发布时间】:2014-08-17 14:34:40
【问题描述】:

我正在将文件上传到我的服务器并获取以下日志,经过大量谷歌搜索后我找不到答案,任何人都可以帮助或建议从哪里开始吗?

2014/06/26 17:15:01 [错误] 15035#0: *2491 FastCGI 在标准错误中发送: “PHP 消息:高度:375 - 宽度:600”,同时读取响应标头 从上游,客户端:,服务器:url,请求:“POST /user/updateProfile HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”, 主机:“url”,引用者:“url/user/edit/7”

出于安全考虑,我已经隐藏了网址。

谢谢!

编辑 *

上传的PHP代码

if(empty($_FILES['user_cover_image_url']['name'])) {
        } else {
            //Cover Elements
            $coverName = $_FILES['user_cover_image_url']['name'];
            $coverExtension=end(explode(".", $coverName));
            if($coverExtension=='png') {$coverExtension = 'jpg';}
            $cName = $uid.'-'.$pass->generateRandomString($length=25);
            $coverImage = $cName.'.'.$coverExtension;
            $cSource = $_FILES['user_cover_image_url']['tmp_name'];
            $cDestination = '/var/www/html/tmp/cover-'.uniqid().'.'.$coverExtension;
            $pass->imageresize($cSource, $cDestination, $width=600, $height=600, $crop=false, $quality=72);
            if ($s3->putObjectFile($cSource, "proaudiosocialstream", $coverImage, S3::ACL_PUBLIC_READ)) {$s3Cover ='http://bucket.s3.amazonaws.com/'.$coverImage;}else{return false;}
            $data['user_cover_image_url'] = $coverImage;
        }

        if(empty($_FILES['user_avatar_url']['name'])) {
        } else {
            //Avatar Elements
            $avatarName = $_FILES['user_avatar_url']['name'];
            $avatarExtension=end(explode(".", $avatarName));
            if($avatarExtension=='png') {$avatarExtension = 'jpg';}
            $aName = $uid.'-'.$pass->generateRandomString($length=25);
            $avatarImage = $aName.'.'.$avatarExtension;
            $aSource = file_get_contents($_FILES['user_avatar_url']['tmp_name']);
            $aDestination = '/var/www/html/tmp/avatar-'.uniqid().'.'.$avatarExtension;
            $pass->imageresize($aSource, $aDestination, $width=400, $height=400, $crop=false, $quality=72);
            if ($s3->putObjectFile($aDestination, "proaudiosocialstream", $avatarImage, S3::ACL_PUBLIC_READ)) {$s3Avatar ='http://bucket.s3.amazonaws.com/'.$avatarImage;}else{return false;}
            $data['user_avatar_url'] = $avatarImage;
        }

【问题讨论】:

  • 能把上传相关的PHP代码贴出来吗?
  • @Saiqi 按要求添加
  • 我看不出为什么在此处标记 codeigniter 的原因很抱歉,如果我错了,但如果您使用 CI,您可以使用 file uploading library ellislab.com/codeigniter/user-guide/libraries/…
  • 它被标记是因为这是我用来构建这个应用程序的框架,但是我选择不使用这个库,因为我需要在文件上传之前对它做一些其他的事情。不过感谢您的评论。
  • @JustinErswell 它不是 php 或上传问题,它的 nginx 和 php-fpm 配置问题。@我遇到了同样的问题。请尝试我的答案,它会起作用的。

标签: codeigniter nginx php


【解决方案1】:

我认为你没有用 nginx 配置 php-fpm

对于 php-fpm,nginx 虚拟主机文件应该是这样的

server {
    listen   80;
    server_name www.trakleaf.in trakleaf.in;
    access_log access_file_path compression;
    error_log error_file_path;
     root   root_directory;
     index  index.html index.htm index.php;
     location / {  
             try_files $uri $uri/ /index.php;
     }
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        if ($uri !~ "^/images/") {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME root_directory$fastcgi_script_name;
    } 

}

【讨论】:

  • 与问题完全无关。问题清楚地表明请求是传递给php的,不需要(重新)配置它。
  • (另外,提供的配置很糟糕。你不应该使用 if($uri) 检查,应该使用位置。)
  • @MaximDounin 我遇到了同样的问题,我已经通过这个配置解决了这个问题。
  • 你没有。或者,更确切地说,没有问题 - 有问题的消息看起来像是来自 php 的一些调试日志,请参阅我上面的评论。
猜你喜欢
  • 2019-11-08
  • 2013-08-28
  • 1970-01-01
  • 2015-11-17
  • 2017-04-07
  • 1970-01-01
  • 1970-01-01
  • 2016-02-24
  • 1970-01-01
相关资源
最近更新 更多