graham23s Posted November 5, 2007 Share Posted November 5, 2007 Hi Guys, mion cracked it, but this isn't creating a thumbnail the original is uploading fine but the thumbnail isn't being created: <?php ## See if it's a first time user $query_user = "SELECT `photo` FROM `users` WHERE `id`='$var_loggedinuserid'"; $results_user = mysql_query($query_user) or die ("Error getting photo 1"); $row = mysql_fetch_array($results_user) or die ("Error getting the photo array"); $photouploaded = $row['photo']; ## HTML form echo ('<div style="border: 1px solid black;padding:10px; background: yellow; color: #000000; font-size: 12px;"><b>Upload your main profile headshot here.</b></div><br />'); echo ("<form action=\"uploadphoto.php\" method=\"post\" enctype=\"multipart/form-data\" />"); echo ("<table class=\"sub_table\" width=\"500\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\">"); echo ("<tr>"); echo ("<td colspan=\"2\" class=\"edit\" align=\"left\"><img src=\"images/upload_headshot.jpg\"></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td align=\"center\"><b>Select a photo to upload</b></td><td align=\"center\"><input name=\"usersphoto\" type=\"file\" size=\"50\" /></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Upload Photo\" /></td>"); echo ("</tr>"); echo ("</table>"); ## HTML form ## Deal with the submission if($_POST['submit']) { $filesize = $_FILES['usersphoto']['size']; $filetype = $_FILES['usersphoto']['type']; $filetemp = $_FILES['usersphoto']['tmp_name']; $filename = $_FILES['usersphoto']['name']; ## vars $maxheight = 500; $maxwidth = 500; $randomnumber = $var_loggedinuser. "-" .time(); ## Allowed file types $allowed_types = array('image/pjpeg','image/gif','image/png','image/jpeg'); if($filesize == 0) { stderr("Upload Failed","No file was uploaded."); include("includes/footer.php"); exit; } if(!in_array($filetype, $allowed_types)) { stderr("Upload Failed","The file you uploaded is not one of the allowed types only .gif and .jpg are allowed."); include("includes/footer.php"); exit; } $imagedimensions = getimagesize($filetemp); $width = $imagedimensions[0]; $height = $imagedimensions[1]; if($width > $maxwidth || $maxheight > 500) { stderr("Upload Failed","Images cannot be larger than $maxwidth x $maxheight, yours was ($width) width and ($height) height, please try again."); include("includes/footer.php"); exit; } ## Rename the file $renamedimage = $randomnumber.".".substr($_FILES["usersphoto"]["name"],strtolower(strlen($_FILES["usersphoto"]["name"]))-3,3); $uploaddirectory = "uploads/".$renamedimage; ## Upload code if(move_uploaded_file($filetemp, $uploaddirectory)) { ## insert the photo in the database $photoquery = mysql_query("UPDATE `users` SET `photo`='$renamedimage' WHERE `id`='$var_loggedinuserid'"); stderr("Upload Successful","Your image has been uploaded successfully."); ############################################# # Thumbnail ############################################# $add = "uploads/$renamedimage"; ///////// Start the thumbnail generation////////////// $n_width = 300; // Fix the width of the thumb nail images $n_height = 300; // Fix the height of the thumb nail imaage $tsrc="thumbs/$renamedimage"; // Path where thumb nail image will be stored /////////////////////////////////////////////// Starting of GIF thumb nail creation/////////// if (@$userfile_type=="image/gif") { $im=ImageCreateFromGIF($add); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); if (function_exists("imagegif")) { Header("Content-type: image/gif"); ImageGIF($newimage,$tsrc); } elseif (function_exists("imagejpeg")) { Header("Content-type: image/jpeg"); ImageJPEG($newimage,$tsrc); } chmod("$tsrc",0777); } ////////// end of gif file thumb nail creation////////////// ////////////// starting of JPG thumb nail creation////////// if($userfile_type == "image/pjpeg"){ $im=ImageCreateFromJPEG($add); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); ImageJpeg($newimage,$tsrc); chmod("$tsrc",0777); } //////////////// End of JPG thumb nail creation ////////// ############################################# # Thumbnail ############################################# include("includes/footer.php"); exit; } } ?> i get no errors telling me whats wrong either, any input would be great cheers Graham Quote Link to comment 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.