Corrupted File After File Upload - file size is different

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
marywang
Forum Newbie
Posts: 1
Joined: Thu Sep 12, 2013 5:54 pm

Corrupted File After File Upload - file size is different

Post by marywang »

Hi,
I'm running on RHEL 6.2, PHP 4.4.9 and Apache 2.2.15, after the most recent upgrade the file upload logic no longer works. Basically, the file upload seems to be uploaded successfully (no errors returned), but the file is corrupted. The file types can be any file types, and the file size of the uploaded file is always larger than original size. I just compared the source .txt file to the destination .txt, the destination file includes "Content-Disposition: form-data; name="file"; filename="final.txt"
Content-Type: text/plain" in the .txt file. Basically, it added extra text to the destination file. I am not sure what is going on.

I'm not sure if I need to configure something in php.ini or httpd.conf with this error. Any help would be appreciated. Mary

Below is the code that I tried to test:
<html>
<body>
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
// echo "Stored in: " . $_FILES["file"]["tmp_name"];
if (file_exists("/tmp/wangtest/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"/tmp/wangtest/" . $_FILES["file"]["name"]);
echo "Stored in: " . "/tmp/wangtest/" . $_FILES["file"]["name"];
}
}
?>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Corrupted File After File Upload - file size is differen

Post by Celauran »

marywang wrote:PHP 4.4.9
Please tell me this is a typo. That version is five years old.
Post Reply