#38092 [NEW]: Upload of Image damages the image

From: Date: Thu, 13 Jul 2006 11:03:45 +0000
Subject: #38092 [NEW]: Upload of Image damages the image
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-99395@lists.php.net to get a copy of this message
From: rene dot schernus at siemens dot com Operating system: RedHat ES30 PHP version: 4.4.2 PHP Bug Type: Unknown/Other Function Bug description: Upload of Image damages the image Description: ------------ If i upload an jpg-file and save the stream to disk my jpg is damaged after this. If i view the "source" of the jpg i can see that the html-form data is appended. "Content-Disposition: form-data; name="userpic"; filename="66_automotive_102x72_1305008.jpg" Content-Type: image/jpeg". The size of the file i doubled. If i set an directive in the apache config like "ForceType image/jpg" and upload again the jpg isn´t damaged. Reproduce code: --------------- Upload Source: <?php $original = $_FILES['userpic']['tmp_name']; $filename = $_FILES['userpic']['name']; if ($original != '') { copy($_FILES["userpic"]["tmp_name"], "./tmp/".$filename); $filename= "./tmp/".$filename; print "<img src=".$filename.">"; $handle = fopen ($original, "rb"); $contents = fread ($handle, filesize ($original)); $len = strlen($contents); $pos = strpos($contents, 'Type:'); #print "<BR>"; #print "<BR>"; print $contents."<BR>"; fclose ($handle); exit; } ?> <FORM enctype="multipart/form-data" method="post"> <TABLE> <TR><TD>&nbsp; <INPUT type='file' name='userpic' /><input name='weilhalt' type='hidden' value='wert'><INPUT type='hidden' name='target_input' value="seite_teaser" /></TD> <TD align='right'><INPUT type='submit' name='confirm' class='button' value='hochladen' /><BR></TD></TR> </TABLE> </form> Expected result: ---------------- A normal upload. Actual result: -------------- Source of uploaded jpg: --snip-- ^@^@^@H^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@8BIM^D^Q^@^@^@^@^@^A^A^@8BIM^D^T^@^@^@^@^@-----------------------------7301164174495^M Content-Disposition: form-data; name="userpic"; filename="66_automotive_102x72_1305008.jpg"^M Content-Type: image/jpeg^M ^M ÿÃÿà ^@^PJFIF^@^A^B^A^@·^@·^@^@ÿí^N¦Photoshop 3.0^@8BIM^Cí^@^@^@^@^@^P^@¶áH^@^B^@^B^@¶áH^@^B^@^B8BIM^D^M^@^@^@^@IM^D^Y^@^@^@^@^@^D^@^@^@^^8BIM^Có^@^@^@^@^@ ^@^@^@^@^@^@^@^@^A^@8BIM^D ^@^@^@^@^@^A^@^@8BIM'^P^@^@^@^@^@ --snip-- -- Edit bug report at http://bugs.php.net/?id=38092&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38092&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38092&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38092&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38092&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38092&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38092&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38092&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38092&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38092&r=support Expected behavior: http://bugs.php.net/fix.php?id=38092&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38092&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38092&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38092&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38092&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38092&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38092&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38092&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38092&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38092&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38092&r=mysqlcfg

« previous php.bugs (#99395) next »