【问题标题】:Different downloaded file depending on the server不同的下载文件取决于服务器
【发布时间】:2017-04-26 13:28:38
【问题描述】:

我将此代码与Symfony 2.8 一起使用:

protected function getFiles(FileBag $bag)
{
    $files = array();
    $fileBag = $bag->all();
    dump($fileBag);
    ....
}

在我的开发环境中(Ubuntu 16.04PHP 5.6Apache 2),$fileBag 很好:

array:1 [▼
  "listing" => array:1 [▼
    "image" => array:1 [▼
      "new" => array:1 [▼
        0 => UploadedFile {#14 ▼
          -test: false
          -originalName: "logo2.gif"
          -mimeType: "image/gif"
          -size: 7719
          -error: 0
          path: "/tmp"
          filename: "phpPymk91"
          basename: "phpPymk91"
          pathname: "/tmp/phpPymk91"
          extension: ""
          realPath: "/tmp/phpPymk91"
          aTime: 2017-04-26 14:49:16
          mTime: 2017-04-26 14:49:16
          cTime: 2017-04-26 14:49:16
          inode: 278115
          size: 7719
          perms: 0100600
          owner: 33
          group: 33
          type: "file"
          writable: true
          readable: true
          executable: false
          file: true
          dir: false
          link: false
        }
      ]
    ]
  ]
]

但是在服务器中(天蓝色Ubuntu 14.04PHP 5.5)我有这个结果:

array:1 [▼
  "listing" => array:1 [▼
    "image" => array:1 [▼
      "new" => array:1 [▼
        0 => UploadedFile {#14 ▼
          -test: false
          -originalName: "logo2.gif"
          -mimeType: "application/octet-stream"
          -size: 0
          -error: 1
          path: ""
          filename: ""
          basename: ""
          pathname: ""
          extension: ""
          realPath: "/var/www/html/web"
          aTime: 1970-01-01 01:00:00
          mTime: 1970-01-01 01:00:00
          cTime: 1970-01-01 01:00:00
          inode: false
          size: false
          perms: 00
          owner: false
          group: false
          type: false
          writable: false
          readable: false
          executable: false
          file: false
          dir: false
          link: false
        }
      ]
    ]
  ]
]

路径、大小、mimeType……都不好。

php.ini 看起来一样。

你有什么想法吗?

【问题讨论】:

  • 图片好像没有保存,请检查保存路径。
  • @PedroLobito:我没关系,但我该如何检查呢?
  • @PedroLobito: upload_tmp_dir 都是空的,我把/tmp 放在服务器的php.ini 中,但是结果是一样的......
  • 您确定 php 对您要写入的目录具有写入权限吗?目录也存在吗?
  • @katona.abel:/tmpexist 我可以对:drwxrwxrwt 3 root root 4096 Apr 26 13:54 tmp/

标签: php symfony file-upload php-ini


【解决方案1】:

php.ini 中缺少 output_buffering = On

感谢您的建议和https://stackoverflow.com/a/37595453/3351765

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    相关资源
    最近更新 更多