Apache application / octet-stream创建一个空文件

时间:2016-11-15 05:07:29

标签: php apache laravel xamarin multipartform-data

我尝试使用Xamarin.Forms应用程序将文件上传到服务器。

var content = new MultipartFormDataContent();
content.Add(new StreamContent(new MemoryStream(img)), "file", "image.jpg");
httpClient.PostAsync(uri, MultipartFormDataContent);

我使用PHP和Symfony UploadedFile类在服务器上接收文件。 这部分适用于我的本地主机(macOS Sierra Version 10.12.1 / Apache/2.4.23 (Unix)),当我进行测试时,我能够收到该文件:

"file" => UploadedFile {#217 ▼
    -test: false
    -originalName: "image.jpg"
    -mimeType: "application/octet-stream"
    -size: 8112955
    -error: 0
    path: "/Applications/MAMP/tmp/php"
    filename: "phpWyUBHM"
    basename: "phpWyUBHM"
    pathname: "/Applications/MAMP/tmp/php/phpWyUBHM"
    extension: ""
    realPath: "/Applications/MAMP/tmp/php/phpWyUBHM"
    writable: false
    readable: false
    executable: false
    file: false
    dir: false
    link: false
  }

Apache配置:

upload_max_filesize 32M 32M
post_max_size       32M 32M

所以我可以移动文件,这是我上传的实际图片。

当我尝试在我的演示服务器(Ubuntu 14.04.5 LTS / Apache/2.4.7 (Ubuntu)上)时,收到的文件实际为空,其大小为0

"file" => UploadedFile {#217 ▼
    -test: false
    -originalName: "image.jpg"
    -mimeType: "application/octet-stream"
    -size: 0
    -error: 0
    path: "/tmp"
    filename: "phppFr9Pr"
    basename: "phppFr9Pr"
    pathname: "/tmp/phppFr9Pr"
    extension: ""
    realPath: false
    writable: false
    readable: false
    executable: false
    file: false
    dir: false
    link: false
  }

Apache配置:

upload_max_filesize 1000M   1000M
post_max_size       1000M   1000M

所以我猜这个问题来自Apache,但我现在已经搜索了很长时间,但找不到任何解决这个问题的提示。

感谢。

编辑1

/ tmp目录的权限是:

drwxrwxrwt 13 root root 4096 Nov 15 14:19

如果我尝试使用Postman发布图像,则/tmp目录已创建良好:

"file" => UploadedFile {#217
    -test: false
    -originalName: "image.jpg"
    -mimeType: "image/jpeg"
    -size: 8112955
    -error: 0
    path: "/tmp"
    filename: "php2LIEcm"
    basename: "php2LIEcm"
    pathname: "/tmp/php2LIEcm"
    extension: ""
    realPath: false
    writable: false
    readable: false
    executable: false
    file: false
    dir: false
    link: false
  }

因此,这意味着apache和php具有在此/tmp目录中写入的权限。

1 个答案:

答案 0 :(得分:0)

区别在于/tmp的权限。执行脚本的用户(如Apache或php)应具有从write/tmpread的权限。