Forum Moderators: coopster
<?php
if (!isset($changestatus)) {
?>
<form method="POST" action="<?=$PHP_SELF?>" enctype="multipart/form-data" />
<input name="userfile" type="file" />
<input name="changestatus" type="submit" value="SUMBIT" />
</form>
<?php
} else {
if ($userfile!= "" ¦¦ $userfile!= NULL) {
echo("Error Code: " . $_FILES['userfile']['error'] . "<br />");
echo("File Size: " . $_FILES['userfile']['size'] . "<br />");
echo("MIME Type: " . $_FILES['userfile']['type']);
move_uploaded_file($userfile, "/var/www/html/filelistings/" . $_FILES['userfile']['name']);
echo("<br />Done");
}
}
?>
Now when I run it the file uploads fine, but the file size is about twice the size of the original file unless it is a plain/text file. .txt files work fine.
This is the output I get uploading a 156129 byte image:
In IE6:
Error Code: 0
Temp Name: /tmp/phpWzn1Gb
File Size: 311777
MIME Type: image/pjpeg
Done
In Mozilla:
Error Code: 0
Temp Name: /tmp/phpr9vlnL
File Size: 312405
MIME Type: image/jpeg
Done
In Opera:
Error Code: 0
Temp Name: /tmp/phpP7GxxO
File Size: 312399
MIME Type: image/jpeg
Done
Different file sizes every time, I have never seen this before.
Any Ideas?
If that is not the problem, try reading the file into a string, use stripslashes(), then re-write the file.
If all else fails, wait for someone else to post a better response. ;-)
noSanity
Thanks
// Open, read, then close the temp file
$input_handler = fopen($userfile, "r");
$file_contents = fread($input_handler, strlen($file_contents));
fclose($input_handler);// Clean up the string
$clean_file_contents = stripcslashes($file_contents);
// Write the file
$new_filename = "/var/www/html/filelistings".$userfile_name;
$output_handler = fopen($new_filename, "w");
fwrite($output_handler, $clean_file_contents, strlen($clean_file_contents));
fclose($output_handler);
------
Perhaps that might work.
noSanity
[edited by: nosanity at 1:01 am (utc) on Mar. 18, 2003]
A) add PHP's General user group (news://news.php.net/php.general) to my favorite news reader, and post a message regarding this topic. Beware, this is a general user group, and it is quite busy. (That is why I didn't suggest going onto the mailing list).
-- OR --
B) Install the latest version of PHP and see if that fixes the problem by itself.
noSanity
FROM:
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 524288
</Files>
TO:
AddType application/x-httpd-php .php
-- OR
Tried the latest RC from PHP?
[qa.php.net ]
noSanity
Sorry to intrude, but I was looking over this discussion and had another thought on what might be the problem (forgive me if I am wrong). Could it not be your FTP program that is at fault, some FTP clients try to upload images in ASCII and that gives back errors alike to what has been suggested.
Just a thought :)
-gs