uploaded file has zero bytes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

uploaded file has zero bytes

Post 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
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Can you post your code for review...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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>";
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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];
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Even then $_FILES['uploadFile'.$x]['name'] should be an array.
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

Post 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.
nayeemmz
Forum Commoner
Posts: 32
Joined: Fri Jun 29, 2007 7:19 pm

solved

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply