By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,615 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,615 IT Pros & Developers. It's quick & easy.

File Sizes Smaller After PHP Upload

P: 224
hi there... i've written a small PHP script to upload files onto my server... but whenever i upload a file, the file size becomes automatically smaller on the server...

for example: i uploaded a 200k jpeg file from my computer, but after upload it lists as 130k on the server. to make sure it wasn't just a wrongfully info display, i downloaded the 130k file on to my computer and listed in the files info window states that infact the downloaded file is 130k, not 200k like the original. the file looks identical to the original 200k file, but the file size is different...

i'm concerned the upload has compressed the jpeg file. this is my code:

HTML code:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. </head>
  6. <body>
  8. <form enctype="multipart/form-data" action="uploadtest.php" method="POST">
  10. <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  11. Choose a file to upload:<br /> <input name="datafileA" type="file" /><br />
  13. <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  14. Choose a file to upload:<br /> <input name="datafileB" type="file" />
  16. <br /><br />
  17. <input type="submit" value="SUBMIT" />
  18. </form>
  20. </body>
  21. </html>
PHP script:
Expand|Select|Wrap|Line Numbers
  1. <?php
  3. $uploadfolder = "uploads/";
  4. $uploadfileA = $uploadfolder . basename($_FILES['datafileA']['name']);
  5. $uploadfileB = $uploadfolder . basename($_FILES['datafileB']['name']);
  7. if    (move_uploaded_file($_FILES['datafileA']['tmp_name'], $uploadfileA))
  8.     { 
  9.     echo "Successful upload File A.\n\n";
  10.     }
  11.     else
  12.     {
  13.     echo "File Field A Was Empty... But That's No Problem.\n\n";
  14. }
  16. if    (move_uploaded_file($_FILES['datafileB']['tmp_name'], $uploadfileB))
  17.     { 
  18.     echo "Successful upload File B.\n\n";
  19.     }
  20.     else
  21.     {
  22.     echo "File Field B Was Empty... But That's No Problem.\n\n";
  23. }
  25. ?>
any ideas why this is happening?
May 4 '07 #1
Share this Question
Share on Google+
2 Replies

P: 136

I not sure what is happening in ur case. According to ur code its seems proper to me. The enctype of the form cause some problem, but in ur case its proper.

For debugging purpose I can suggest u should the check the file size before moving it to the desired upload folder from temp folder.

[PHP]$fileSizeA = filesize($_FILES['datafileA']['tmp_name']);
echo $fileSizeA;
if (move_uploaded_file($_FILES['datafileA']['tmp_name'], $uploadfileA))

May 5 '07 #2

Expert 5K+
P: 5,821
It is possible that your server Uses a different addressing system than your client computer. Basically, your hard drive has x amount of data, and that space is divided into some really huge number of available blocks. The smallest amount of space any file can take up is one block. Beyond that, I'm not sure exactly how it works, but that's why a text file with one character in it could be reported as being "4KB" in size.

Likewise, it could be that your JPEG file is only 160KB, but the client allocates 200KB of hard drive space because of the size of its address blocks.

Here's a really complicated explanation of what I think I just said:

You could test to make sure your image is not being compressed by:
- Uploading a ZIP'ed jpeg and unzipping it on the server and comparing the size of the JPEG files, or
- Downloading the jpeg immediately after it is received and comparing the sizes on your client machine, or
- Downloading the jpeg immediately after it is received and diff'ing the files.
May 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.