473,503 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Sizes Smaller After PHP Upload

chunk1978
224 New Member
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>
  5.  
  6. <body>
  7.  
  8. <form enctype="multipart/form-data" action="uploadtest.php" method="POST">
  9.  
  10. <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  11. Choose a file to upload:<br /> <input name="datafileA" type="file" /><br />
  12.  
  13. <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
  14. Choose a file to upload:<br /> <input name="datafileB" type="file" />
  15.  
  16. <br /><br />
  17. <input type="submit" value="SUBMIT" />
  18. </form>
  19.  
  20. </body>
  21. </html>
  22.  
PHP script:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $uploadfolder = "uploads/";
  4. $uploadfileA = $uploadfolder . basename($_FILES['datafileA']['name']);
  5. $uploadfileB = $uploadfolder . basename($_FILES['datafileB']['name']);
  6.  
  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. }
  15.  
  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. }
  24.  
  25. ?>
  26.  
any ideas why this is happening?
May 4 '07 #1
2 1687
devsusen
136 New Member
Hi,

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))
{
................
[/PHP]

susen
May 5 '07 #2
pbmods
5,821 Recognized Expert Expert
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:
http://www.dewassoc.com/kbase/hard_d...imitations.htm

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

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

Similar topics

11
6387
by: Thomas Mlynarczyk | last post by:
Hello, I want to upload files via an HTML form and store them somewhere on my webspace. So far so good. I am just a bit concerned about security issues and traffic. My provider has set a file...
5
5432
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
1
2189
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for...
12
695
by: Ken | last post by:
How can I determine a image file size before uploading it? I would like to make sure the size is under a maximum before taking the time to upload it. If I have to upload the file before...
1
2111
by: Ron Vecchi | last post by:
I am using asp.net to upload an image and then perform resizing on it and saving the different sizes to file. The resized images were coming up and being displayed in the bowser fine but the image...
1
1587
by: Ron Vecchi | last post by:
When posting a file upload I have taken in consideration the maxRequestLength and set it accordingly. In my case where a posibility of a 30 meg file can be uploaded I set it to 30720. Although...
4
1526
by: Manu | last post by:
I want my user to upload a file to the site. Let us say a word file to be saved in the database for other users of the site to use. How can this be done? Is there a web control for that?
12
7742
by: JMB | last post by:
Hello, I was wondering if anyone knew of any projects extending the inline upload progress bar to utilize an inpage image uploader with bar, without having to refresh or go to a seperate page,...
7
7121
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.