Page 1 of 1

uploaded file has zero bytes

Posted: Mon Sep 03, 2007 2:56 am
by nayeemmz
Hi,

I am uploading multiple files.

The files get uploaded without any error but the last file always shows as zero byte size.

This problem is driving me nuts.

I would appreciate any pointers to solve the problem.

Thanks

-Nayeem

Posted: Mon Sep 03, 2007 3:19 am
by CoderGoblin
Can you post your code for review...

Posted: Mon Sep 03, 2007 3:33 am
by anjanesh
Why dont you post your print_r($_FILES) result ?

Wild Guess : You're interpreting the array as $_FILES['userfile'][$i]['name'] instead of $_FILES['userfile']['name'][$i]

Code: Select all

$n = count($_FILES['userfile']['name']);
echo $_FILES['userfile'][$n-1]['size']."\n<br>";
echo $_FILES['userfile']['size'][$n-1]."\n<br>";

Posted: Mon Sep 03, 2007 11:38 am
by nayeemmz
Here is part of code which does the uploading part based on the number of files specified by the user to upload in the form

Code: Select all

$uploadNeed = $_POST['uploadNeed'];

//start for loop
 if(isset($_SESSION))
 {
// Run through all the uploaded files
 for($x=0; $x<$uploadNeed;$x++)
 {
  $file_name = $_FILES['uploadFile'.$x]['name'];
  // strip file_name of slashes
  $file_name = stripslashes($file_name);
  $file_name = str_replace("'","",$file_name);
if(!ssh2_scp_send ($ss_connect,$_FILES['uploadFile'.$x]['tmp_name'],targetfile,0744))
     {
       echo "Problem: Could not move $file_name into directory";
       display_user_menu();
       do_html_footer();
       exit;
    }
}
This just a part of code which does the uploading part.

After the uploading is complete, when I check the files size on the file server I see that the last file that has been uploaded has a zero size.

Thanks for looking into it.

-Nayeem

Posted: Mon Sep 03, 2007 11:44 am
by anjanesh
Odd that you are doing

Code: Select all

$file_name = $_FILES['uploadFile'.$x]['name'];
It should be something like

Code: Select all

$file_name = $_FILES['uploadFile']['name'][$x];

Posted: Mon Sep 03, 2007 11:55 am
by nayeemmz
I am sorry that is not the problem

My code statement is trying to give the name to the file based on its number.
This is not a cause of zero bytes being uploaded. I have tested it.

Thanks

Posted: Mon Sep 03, 2007 12:03 pm
by anjanesh
Even then $_FILES['uploadFile'.$x]['name'] should be an array.

Posted: Mon Sep 03, 2007 12:08 pm
by nayeemmz
Yes sure.

I don't really understand what you are trying to say?

All the files get uploaded perfectly fine except the last one, regardless of what it is.

solved

Posted: Mon Sep 03, 2007 3:36 pm
by nayeemmz
Hi,

I solved the problem by checking the file size of the uploaded file and re-uploading it in case the uploaded file size was zero.

This solved it

Posted: Mon Sep 03, 2007 10:08 pm
by s.dot
That didn't solve it. That is just a workaround. You shouldn't have to check that.

Your input fields should be like this:

Code: Select all

<input type="file" name="fileUpload[]" size="20" />
<input type="file" name="fileUpload[]" size="20" />
That way you eliminate numbering in your processing script, and you can easily loop through the entire set of uploaded files, no matter if there are 100 or 1.