文件上传导致文件大小为0

文件上传导致文件大小为0

本文介绍了文件上传导致文件大小为0,错误代码为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像上传到php脚本.我有一个非持久性错误,导致某些上载的图像的文件大小为0.我试图将_FILES数组打印到我的日志文件中,并且显示错误代码为0,应该可以

I'm trying to upload an image to a php script. I have a, non-persistent, bug that results in some of the images uploaded has a file size of 0. I have tried to print the _FILES array to my log file, and it shows the error code being 0, which should be ok.

这些行:

foreach($_FILES['image_file'] as $key => $val){
      error_log(date('j/n/o H:i:s')." ". $key ." => ".$val. "\n", 3,$log_path);
    }

在日志文件中给我这些信息

Give me these in the log file:

  1. 2012年3月10日12:12:54名称=> 59175248636.jpg
  2. 2012年3月10日12:12:54类型=>图片/jpeg
  3. 2012年3月10日12:12:54 tmp_name => C:\ WINDOWS \ Temp \ php411F.tmp
  4. 2012年3月10日12:12:54错误=> 0
  5. 2012年3月10日12:12:54大小=> 0

可以从日志文件中读取该脚本,该脚本在Windows机器上运行,据我所知.我已经在php.ini中将post_max_size更改为10M,并将upload_max_size更改为10M.

As can be read from the log file, this script runs on a Windows machine, of which I have limited knowledge. I have already changed the post_max_size to 10M, as well as upload_max_size to 10M in the php.ini.

我对此问题感到震惊.当我在自己的设备上进行测试时,它可以正常工作,但是由于某些原因,当我的测试人员尝试该程序时,它会失败.

I am flabbergasted about this issue. When I test from my own devices, it works fine, but for some reason, when my testers try it out, it fails.

推荐答案

编辑-尝试以下操作:

我认为您可能需要将$ _FILES ['file']更改为$ _FILES ['image_file']才能使用您的设置.为了便于阅读,我将其保留如下.

I think you may need to change $_FILES['file'] to $_FILES['image_file'] to work with your setup. I have left it as below for ease of reading...

if ($_FILES['file']['error'] === UPLOAD_ERR_OK && $_FILES['file']['size'] > 0){

   ... upload was successful ...

}elseif($_FILES['file']['error'] === UPLOAD_ERR_OK && $_FILES['file']['size'] == 0){

   die("Upload failed, random upload issue... please try again);
   // change this error to something more useful... (leave this error in for testing)

}else {

   die("Upload failed with error code " . $_FILES['file']['error']);

}

这不能解决随机文件大小的问题,但可以使您的代码/过程继续进行.将其视为上传失败,并告诉用户重试...

This doesn't solve the random filesize issue, but it will allow your code / process to continue. Treat it as a failed upload and tell the user to try again...

stackoverflow帖子中使用的代码. com/users/118068/marc-b>马克B

Used code from this stackoverflow post posted by Marc B

这篇关于文件上传导致文件大小为0,错误代码为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 19:57