Hi there i have a upload script in which it uploads the picture to a folder than creates two thumbnails in different folders however it is uploading the image and saving it in the folder /photos/ then its NOT uploading the thumbnail i created to photos/thumbs/ but it is uploading the second thumbnail to /photos/thumbs/forum/ please help me so the script will upload the 1st thumbnail as well.
here is the script Code: <?php session_start(); include_once"../includes/db_connect.php"; $username=$_SESSION['username']; if(!$username){header("Location: ../login.php");} $fetch=mysql_fetch_object(mysql_query("SELECT Username, photo, id FROM members WHERE Username='$username'"));
//define a maxim size for the uploaded images in Kb define ("MAX_SIZE","300");
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; }
//This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); //if it is not a known extension, we will suppose it is an error and will not upload the file, //otherwise we will do more tests if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message $output="<span class='unsuccess'>The $extension file format is not supported</span>"; $say="1"; $show="yes"; $errors=1; } else { //get the size of the image in bytes //$_FILES['image']['tmp_name'] is the temporary filename of the file //in which the uploaded file was stored on the server $size=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger if ($size > MAX_SIZE*1024) { $output="<span class='unsuccess'>Your file is bigger than 100KB</span>"; $say="1"; $show="yes"; $errors=1; } //delete the files if it exists $jpg = "../user/photos/$fetch->id"."."."jpg"; $gif = "../user/photos/$fetch->id"."."."gif"; $png = "../user/photos/$fetch->id"."."."png";
if (file_exists($jpg)) { $myFileJPG ="../user/photos/$fetch->id"."."."jpg"; unlink($myFileJPG); } if (file_exists($gif)) { $myFileGIF ="../user/photos/$fetch->id"."."."gif"; unlink($myFileGIF); } if (file_exists($png)) { $myFilePNG ="../user/photos/$fetch->id"."."."png"; unlink($myFilePNG); } ////// DELETE THE PREVIOUS THUMBS if (file_exists($jpg2)) { $myFileJPG2 ="../user/photos/thumbs/$fetch->id"."."."jpg"; unlink($myFileJPG2); } if (file_exists($gif2)) { $myFileGIF2 ="../user/photos/thumbs/$fetch->id"."."."gif"; unlink($myFileGIF2); } if (file_exists($png2)) { $myFilePNG2 ="../user/photos/thumbs/$fetch->id"."."."png"; unlink($myFilePNG2); } ///// DELETE THE PERVIOUS FORUM THUMBS if (file_exists($jpg3)) { $myFileJPG3 ="../user/photos/thumbs/forum/$fetch->id"."."."jpg"; unlink($myFileJPG3); } if (file_exists($gif3)) { $myFileGIF3 ="../user/photos/thumbs/forum/$fetch->id"."."."gif"; unlink($myFileGIF3); } if (file_exists($png3)) { $myFilePNG3 ="../user/photos/thumbs/forum/$fetch->id"."."."png"; unlink($myFilePNG3y); } //we will give an unique name, for example the time in unix time format $image_name=$fetch->id.'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname="photos/".$image_name; $newname2="photos/thumbs/".$image_name; $newname3="photos/thumbs/forum/".$image_name; //we verify if the image has been uploaded, and print error instead $copied = copy($_FILES['image']['tmp_name'], $newname); $copied2 = copy($_FILES['image']['tmp_name'], $newname2); $copied3 = copy($_FILES['image']['tmp_name'], $newname3); if (!$copied) { $output="<span class='unsuccess'>There is an error with that image try again!</span>"; $say="1"; $show="yes"; $errors=1; } if (!$copied2) { $output="<span class='unsuccess'>There is an error with that image try again!</span>"; $say="1"; $show="yes"; $errors=1; } if (!$copied3) { $output="<span class='unsuccess'>There is an error with that image try again!</span>"; $say="1"; $show="yes"; $errors=1; } }}} //If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { $output="<span class='success'>Successful, You May Now Close This Window</span>"; $say="1"; $show="no"; ///////////////////// THIS IS THE FIRST THUMBNAIL NOT WORKING !!!!! if($extension == "jpg"){ $im = imagecreatefromjpeg( "../user/photos/$image_name" ); } if($extension == "gif"){ $im = imagecreatefromgif( "../user/photos/$image_name" ); } if($extension == "png"){ $im = imagecreatefrompng( "../user/photos/$image_name" ); } $ox = imagesx( $im ); $oy = imagesy( $im );