sparq Posted November 26, 2009 Share Posted November 26, 2009 The basic process of this php code is to take the submitted file, convert it to a small JPG thumbnail and put it into one directory and save the original file into another, but it seems that when using PNG images it doesn't quite work, any ideas? if((($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/jpeg") || ($FILES['file']['type'] == "image/pjpeg")) && ($_FILES['file']['size'] < 2000000000)) { if($_FILES['file']['error'] > 0) { echo '<script language="javascript" type="text/javascript">window.top.window.upload_error(' . $_FILES['file']['error'] . ');</script>'; } else { $fileName = $_FILES['file']['name']; $f_ext = "." . strtolower(substr(strrchr($fileName, '.'), 1)); $time = time(); $f_noext = $time.substr(microtime(),2,3); $f_name = $time.substr(microtime(),2,3) . $f_ext; if(file_exists("img/" . $f_name)) { echo $_FILES['file']['name'] . " already exists."; } else { move_uploaded_file($_FILES['file']['tmp_name'], "img/" . $f_name); $image_path = "img/" . $f_name; $fsize = getimagesize($image_path); $max_d = ($orig_p==0)? 250 : 125; $img = null; $ext = strtolower(end(explode('.', $image_path))); if($ext == 'jpg' || $exit == 'jpeg') { $img = @imagecreatefromjpeg($image_path); } else if($ext == 'png') { $img = @imagecreatefrompng($image_path); } else if ($ext == 'gif') { $img = @imagecreatefrompng($image_path); } if($img) { $w = imagesx($img); $h = imagesy($img); $width = imagesx($img); $height = imagesy($img); $scale = min($max_d/$width, $max_d/$height); if($scale < 1){ $new_width = floor($scale *$width); $new_height = floor($scale*$height); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresized($tmp_img, $img, 0,0,0,0,$new_width,$new_height,$width,$height); imagedestroy($img); $img = $tmp_img; ImageJPEG($img, 'thumb/' . $f_noext . 't.jpg',60); imagedestroy($tmp_img); echo '<script language="javascript" type="text/javascript">window.top.window.stopUpload();</script>'; } } } } } Link to comment https://forums.phpfreaks.com/topic/183013-image-upload-script-not-working-with-png/ Share on other sites More sharing options...
cags Posted November 26, 2009 Share Posted November 26, 2009 Your code only accepts image/gif, image/jpeg, image/pjpeg. If you wish to allow png you will have to add image/png. Link to comment https://forums.phpfreaks.com/topic/183013-image-upload-script-not-working-with-png/#findComment-965940 Share on other sites More sharing options...
sparq Posted November 27, 2009 Author Share Posted November 27, 2009 Oh wow I didn't think it was that easy for some reason I looked past that little part of the code without any consideration. Thanks though. Link to comment https://forums.phpfreaks.com/topic/183013-image-upload-script-not-working-with-png/#findComment-966286 Share on other sites More sharing options...
keldorn Posted November 27, 2009 Share Posted November 27, 2009 If you use Asido, you can make you code alot less. Plus its awseme. Link to comment https://forums.phpfreaks.com/topic/183013-image-upload-script-not-working-with-png/#findComment-966321 Share on other sites More sharing options...
sparq Posted November 27, 2009 Author Share Posted November 27, 2009 Nice thanks. I'll make sure I take a look at implementing that once I get some other bugs worked out in the rest of the code. Link to comment https://forums.phpfreaks.com/topic/183013-image-upload-script-not-working-with-png/#findComment-966674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.