davie_uk Posted November 26, 2012 Share Posted November 26, 2012 (edited) I'm hoping someone can help me on this. Ive been using this piece of code for years, but my webserver just got upgrade to PHP5, and now I cant upload any images!! I'm guessing that some elements are no longer compatible in PHP, but havent a clue where to start. Maybe someone with a better trained eye can spot something, apart from my terrible coding skills. Any help would be greatly appreciated. // ....................................... MY UPLOAD SCRIPT STARTS// define ("MAX_SIZE","5000000000"); define ("WIDTH","400"); define ("WIDTHth","75"); function make_thumb($img_name,$filename,$new_w,$new_h) { $ext=getExtension($img_name); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name); $old_x=imageSX($src_img); $old_y=imageSY($src_img); $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); imagedestroy($dst_img); imagedestroy($src_img); } function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['btn_welcomepic'])) { $image=$_FILES['nwbpswelcomepic_pic']['name']; if ($image) { $filename = stripslashes($_FILES['nwbpswelcomepic_pic']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=getimagesize($_FILES['nwbpswelcomepic_pic']['tmp_name']); $sizekb=filesize($_FILES['nwbpswelcomepic_pic']['tmp_name']); if ($sizekb > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } $image_name=time().'.'.$extension; $newname="test/".$image_name; $copied = copy($_FILES['nwbpswelcomepic_pic']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { $imgphoto='photo_'.$image_name; $thumb_name='../../../images/welcome/photo_'.$image_name; $thumb=make_thumb($newname,$thumb_name,WIDTH); $imgthumb='thumb_'.$image_name; $thumb_name='../../../images/welcome/thumb_'.$image_name; $thumb=make_thumb($newname,$thumb_name,WIDTHth); $deleteimagefile="../../../images/welcome/".$image_name; unlink($deleteimagefile); }} }} // ....................................... MY UPLOAD SCRIPT ENDS// Edited November 26, 2012 by PFMaBiSmAd added code tags Quote Link to comment https://forums.phpfreaks.com/topic/271215-php4-to-php5-image-upload/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 26, 2012 Share Posted November 26, 2012 and now I cant upload any images!! How do you know you can't upload any images? You didn't state the symptom or error you get that tells you that the code doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/271215-php4-to-php5-image-upload/#findComment-1395350 Share on other sites More sharing options...
Backslider Posted November 26, 2012 Share Posted November 26, 2012 The code look ok to me at a glance - probably a permissions problem where you are saving the image to. What is the error? Quote Link to comment https://forums.phpfreaks.com/topic/271215-php4-to-php5-image-upload/#findComment-1395351 Share on other sites More sharing options...
davie_uk Posted November 26, 2012 Author Share Posted November 26, 2012 I dont seem to be experiencing any errors. I monitor my internet after i hit the submit button; it clearly uploads in some way or form, and IE loads the following page to say upload complete. The destination folder permissions are correct, but nothing appears in the folder. It's left me rather puzzled. http://www.wiltonandbarfordprimaryschool.co.uk/phpinfo.php Quote Link to comment https://forums.phpfreaks.com/topic/271215-php4-to-php5-image-upload/#findComment-1395358 Share on other sites More sharing options...
PFMaBiSmAd Posted November 26, 2012 Share Posted November 26, 2012 (edited) IE loads the following page to say upload complete Since nothing you posted shows how your code is going to a 'following' page, your first step would be to post all the relevant code needed to reproduce the problem. Best guess (as a general rule don't expect people to visit links you put in your posts) is you have output buffering turned on in your master php.ini and this is hiding any messages you are displaying and your code is unconditionally redirecting to your 'following' page. Edited November 26, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/271215-php4-to-php5-image-upload/#findComment-1395366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.