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
Database 'Validation'
Hi everyone,I'm trying to validate the password entered by the user with the password in the database. I've worked out that it checks the username fine (if the username doesn't exist it displays an
onClick='location.href=index.htm'> not working
Below is my code:echo "<input type='button' value='redirect' onClick='location.href=index.htm'>";what is wrong with the code?? it's not working
printing links
Hi every1i am connecting to a table in sql and the looping through with a while ($ var = my sql fetch array)the question i have is that when i print_r($var)i get the associative array of all elements
What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is going wrong. It's a set of filters for events. The filter marked "type" (category) works
Change Web page language
i doing this thing first time but i dont find any suitable solution for it. On the demand of user. I want to change my web site pages in user's language without without google translater. Can
Help on code output
My CODE:Code: [Select] echo "<phone>".$line["phone"]."</phone>"; echo
Format timestamp from mysql
When I tried this:Code: date("m/d/Y H:i A", $row['timestamp'])I got 12/31/1969 18:33 PM, so I know the time section is working at least. How can I get the mm/dd/yyyy section to work
How to limit the calls to an API
Hello, in my simple script I call an api which effectively involves me getting an xml file.However the problem is everytime I get a visitor to the webpage it calls the API which means lots of wasteful
Do something every fifth time?
I'm trying to write a loop, but I want it to do something different after every fifth instance. Like, I want it do something like this:Quoteecho $a1;echo $a2;echo $a3;echo $a4;echo $a5.$b;echo $a6;And
PHP Search Issue
Hi, I am using the following code to search and return flights from a database. The user searches by inputting a DepID and an ArrID and I want to display only flights that match both DepID and ArrID.