douzhai7873
2016-11-26 06:25
浏览 52
已采纳

PHP - 在Azure上大文件上载后$ _FILES为空

I've setup an Angular based file upload using the ng-file-upload plugin (https://github.com/danialfarid/ng-file-upload) and I've been handling the file upload with a PHP script.

The file upload and script work on smaller files (tested it on < 1MB), but fails on a larger file (9MB). This leads me to believe that there's a file upload issue. However, I've already created a .user.ini file in the /wwwroot folder with a single line:

upload_max_filesize=20M

Is there another reason why the $_FILES and $_POST arrays would be empty?

JS Code:

Upload.upload({
    url: '/scripts/receiveFile.php',
    file: file
}).then(function(resp) {
    console.log(resp.data);
}, function(resp) {
    console.log(resp.data);
}, function(evt) {
    var progressPercent = parseInt(100.0 * evt.loaded / evt.total);
    console.log(progressPercent + "%");
});

HTML Code:

<div>
    <h1>Upload</h1>
    <input type="file" accept=".zip" ngf-select="submitFile($file)"></input>
</div>

PHP Code:

$file_name = basename($_FILES['file']['name']);
$file_tmp_name = $_FILES['file']['tmp_name'];

The script fails because 'file' is undefined in the $_FILES array - because the $_FILES array is empty.

Thanks!

图片转代码服务由CSDN问答提供 功能建议

我使用ng-file-upload插件设置了基于Angular的文件上传( https://github.com/danialfarid/ng-file-upload )我一直在处理文件 使用PHP脚本上传。

文件上传和脚本适用于较小的文件(在<1MB上测试),但在较大的文件(9MB)上失败。 这让我相信存在文件上传问题。 但是,我已经使用一行在/ wwwroot文件夹中创建了一个.user.ini文件:

  upload_max_filesize = 20M 
    
 
 

还有另一个原因,$ _FILES和$ _POST数组是空的吗?

JS代码:

  Upload.upload({
 url:'/ scripts/receiveFile.php',
n file:  file 
})。then(function(resp){
 console.log(resp.data); 
},function(resp){
 console.log(resp.data); 
},function(  evt){
 var progressPercent = parseInt(100.0 * evt.loaded / evt.total); 
 console.log(progressPercent +“%”); 
}); 
   \  n 
 

HTML代码:

 &lt; div&gt; 
&lt; h1&gt;上传&lt; / h1&gt; 
&lt; input type =“file”accept =  “.zip”ngf-select =“submitFile($ file)”&gt;&lt; / input&gt; 
&lt; / div&gt; 
   
 
 

PHP代码:

  $ file_name = basename($ _ FILES ['file'] ['name']); 
 $ file_tmp_name = $ _FILES ['file'] ['tmp_name']; \  n   
 
 

脚本失败,因为'_FILES数组中未定义'file' - 因为$ _FILES数组为空。

谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsdt66064367 2016-11-26 06:33
    已采纳

    PHP has a confusing was of doing file uploads. To set a larger upload size, you should set both upload_max_filesize and post_max_size. These can be independently different values, as they do different things.

    post_max_size is the maximum file size that can be sent in a POST request to the PHP script. upload_max_filesize is the maximum file size allowed via any method.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题