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";
$jpg2 = "../user/photos/thumbs/$fetch->id"."."."jpg";
$gif2 = "../user/photos/thumbs/$fetch->id"."."."gif";
$png2 = "../user/photos/thumbs/$fetch->id"."."."png";
$jpg3 = "../user/photos/thumbs/forum/$fetch->id"."."."jpg";
$gif3 = "../user/photos/thumbs/forum/$fetch->id"."."."gif";
$png3 = "../user/photos/thumbs/forum/$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 );
$nx = 50;
$ny = 50;
$nm = imagecreatetruecolor( $nx, $ny );
imagecopyresized( $nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy );
if($extension == "jpg"){imagejpeg( $nm, "photos/thumbs/$image_name" );}
if($extension == "gif"){imagegif( $nm, "photos/thumbs/$image_name" );}
if($extension == "png"){imagepng( $nm, "photos/thumbs/$image_name" );}
////////////////// THIS IS THE SECOND WHICH IS WORKING!
if($extension == "jpg"){ $im2 = imagecreatefromjpeg( "../user/photos/$image_name" ); }
if($extension == "gif"){ $im2 = imagecreatefromgif( "../user/photos/$image_name" ); }
if($extension == "png"){ $im2 = imagecreatefrompng( "../user/photos/$image_name" ); }
$ox2 = imagesx( $im2 );
$oy2 = imagesy( $im2 );
$nx2 = 80;
$ny2 = 80;
$nm2 = imagecreatetruecolor( $nx2, $ny2 );
imagecopyresized( $nm2, $im2, 0, 0, 0, 0, $nx2, $ny2, $ox2, $oy2 );
if($extension == "jpg"){imagejpeg( $nm2, "photos/thumbs/forum/$image_name" );}
if($extension == "gif"){imagegif( $nm2, "photos/thumbs/forum/$image_name" );}
if($extension == "png"){imagepng( $nm2, "photos/thumbs/forum/$image_name" );}
mysql_query("UPDATE members SET photo='$image_name' WHERE Username='$username'");
}
/// SETTING AND MAKING THE THUMBS
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Profile Photo</title>
<style type="text/css">
body {
background-image: url(../images/BGs/user/popBG.png);
background-repeat: repeat-x;
background-attachment: fixed;
}
#fingScroll {
overflow: auto;
height: 200px;
}
#title{
height:28px;
background:#FF0;
color:#333;
width:500px;
font-family: "Arial Black", Gadget, sans-serif;
font-size: 18px;
border-top: #000 1px solid;
border-left: #000 1px solid;
border-right: #000 1px solid;
}
#main{
background:#CCC;
color:#000;
width:500px;
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
border-left: #000 1px solid;
border-right: #000 1px solid;
border-bottom: #000 1px solid;
}
p {
margin:0px;
padding:0px;
}
.success {
color: #090;
font-weight: bold;
}
.buttonSmall {
background:url(../images/buttons/blueSmall2.gif);
height:23px;
font-family:Verdana, Geneva, sans-serif;
font-size:14px;
font-weight:bold;
color:#333;
border:#999 1px solid;
}
.buttonSmall:hover {
background:url(../images/buttons/blueSmall1.gif);
height:23px;
font-family:Verdana, Geneva, sans-serif;
font-size:14px;
font-weight:bold;
color:#333;
border:0px;
border:#999 1px solid;
}
</style>
</head>
<body>
<div id="fingScroll" align="center">
<div id="title" align="center">Upload Your Profile Photo</div>
<div id="main" align="center">
<p> <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
<?php if($say=="1"){echo"$output";}?>
<?php if($show!=="no"){?>
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input name="image" type="file"></td></tr>
<tr><td><input name="Submit" type="submit" class="buttonSmall" value="Upload image"></td></tr>
</table>
</form>
<?php }?>
</p>
<p> </p>
</div>
</div>
</body>
</html>
PLEASE HELP ME
Filtering Tables
Hello Thanks for any help any one can give Im very new to PHP..I need to pull data for clients that share 2 diff services into one table.mysql_select_db($database_pull, $pull);$query_Recordset1 =
quick question about System Change Number(SCN) in FlashBack Query topic
i know tht we can get the SCN of the database using flashback concept as follows
cookie problem
I hv a website url In this site main menu functionality based on cookie when user click on particular menu the visited menu change its color and cookie is created for that menu and when user click on
read integers that returns a negative or prints the average
Im trying to finish this homework assignment by tommarow afternoon and I keep getting stuck.
Displaying an image using echo command
I had done a query on my database, one of the fields being an image reference to a directory where an image is stored. e.g "/images/picture.jpg"I want to display this image by using
Problem with PHP/mySQL login code
Hello,There is an error in my login script and I can't figure out what it is...I believe it might be my "SELECT" statement...Can anyone help me? Code: <?php//define ('SASI Services
frames get header location..
i have two frames, one top, one bottom. how do i do a form on the bottom frame that gives me the url of the top frame.is it get header location?.. if so how do i use it to get the top frames url.is
Extracting URL pointer within XML tag
Hi.I'm trying to extract text between two quotation marks in XML. For example, I want to extract:<a href="www.thisisanexample.com">Click here</a>. I want to
array ...
hiCode: function formatCategories($categories, $parentId){ // $navCat stores all children categories // of $parentId $navCat = array(); // expand only the categories with the same parent id
IP Based Cron Jobs
I run cronjobs on my website. After one of my visitors got curious and tinkered around he realized he could reset my cron jobs...woohoo....Is there a way to get information from the server to make