rik72 Posted October 19, 2008 Share Posted October 19, 2008 I'm currently creating a new site out of old code and came across an old script i need help fixing; Here's what i've got; (code wise) <?php include('include/session.php'); if($session->logged_in){ ini_set("session.gc_maxlifetime","10800"); ini_set("upload_max_size","4194304"); $default = $_POST["default"]; $username = $session->userinfo['username']; if(isset($_FILES)) { $fileName = $_FILES["uploadfile"]["name"]; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // make the random file name do{ $randName = md5(rand() * time()); $pass = "$randName.$ext"; $Check = (file_exists("upimg/$pass") || file_exists("thimg/$pass") || file_exists("avimg/$pass")); }while( $Check ); $uploadedfile = $_FILES["uploadfile"]["tmp_name"]; list($width,$height)=getimagesize($uploadedfile); $newwidth1=600; $newwidth2=180; $newwidth3=100; $newheight1=($height/$width)*600; $newheight2=($height/$width)*180; $newheight3=($height/$width)*100; switch($_FILES['uploadfile']['type']) { case "image/gif": $src = imagecreatefromgif($uploadedfile);//Create from GIF! $type = "gif"; break; case "image/jpg": case "image/jpeg": $src = imagecreatefromjpeg($uploadedfile);//Create from JPEG! $type = "jpg"; break; } #1 //$src = imagecreatefromjpeg($uploadedfile);//Create from JPEG! $tmp1=imagecreatetruecolor($newwidth1,$newheight1); imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height); $filename = "upimg/$pass";// . $_FILES["uploadfile"]["name"]; if($type == "gif") { imagegif($tmp1,$filename,100); }elseif($type == "jpg"){ imagejpeg($tmp1,$filename,100); } imagedestroy($src); #2 $tmp2=imagecreatetruecolor($newwidth2,$newheight2); imagecopyresampled($tmp2,$tmp1,0,0,0,0,$newwidth2,$newheight2,$newwidth1,$newheight1); $filename = "thimg/$pass";// . $_FILES["uploadfile"]["name"]; if($type == "gif") { imagegif($tmp2,$filename,100); }elseif($type == "jpg"){ imagejpeg($tmp2,$filename,100); } imagedestroy($tmp1); #3 $tmp3=imagecreatetruecolor($newwidth3,$newheight3); imagecopyresampled($tmp3,$tmp2,0,0,0,0,$newwidth3,$newheight3,$newwidth2,$newheight2); $filename = "avimg/$pass";// . $_FILES["uploadfile"]["name"]; if($type == "gif") { imagegif($tmp3,$filename,100); }elseif($type == "jpg"){ imagejpeg($tmp3,$filename,100); } imagedestroy($tmp2); imagedestroy($tmp3); $name = $_FILES["uploadfile"]["name"]; }} # $query = "INSERT INTO track9_userphotos (pictureurl, username, caption) VALUES('$pass', '$username', '$caption')"; # mysql_query($query) or die(mysql_error()); if ( $default == 1 ) { # $query = "UPDATE altshop_hocsite SET photo='$pass' WHERE username='$username'"; # mysql_query($query) or die(mysql_error()); } else { echo ""; } ?> <h8>Your Uploaded Picture</h8><p><div id='header2'> <br><br> <table border="0" width="700" cellspacing="0" cellpadding="0"> <tr> <td width="200" valign="top"> <p align="center"><? echo "<img src='thimg/$pass'>"; ?></p> <p></td> <td> <p align="center"> <p align="center"> </p> </form> <p></td> </tr> </table> </div> Here's what i've got; (error wise) Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/altshop/public_html/new/uploader.php on line 47 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/altshop/public_html/new/uploader.php on line 55 Your Uploaded Picture Link to comment https://forums.phpfreaks.com/topic/129139-solved-image-uploader-errors/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.