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
Problem with HTML form
Hello,I made a HTML form with some fields and check box.Everything works fine except when i receive the email, only fields appear in the email not the content of the check box.I have attached the
Problem with "dynamic" index page
Hi. I have one question. In my index.php page I have this kind of code:Code: // listaa sivut$pages = Array ("etusivu" => "etusivu.php",,"linkit" =>
have trouble in a if condition
The if below is working ok, it check when indexes, name, zipcode and state are empty.Code: <?php if ( trim($_POST['name']) == '' && $_POST['zipcode'] =='' &&
Display error above the login forum help!
Hi guys. just so you know im not asking for someone to do this for me I just need to be pointed in the right direction...here is my problem. I have index.php in that file i have included login.php
division gives infinity anser
int main(){ int z=0; int i=1/z; cout<<i;}It doesn't throw any error in Visual Studio 2008. .......What setting one has to change so that it will show runtime error in VS 2008.....
help with mysql_error()
Hi,I am trying to insert data into a table, but I am not able to insert it. I wanted to see what the error was using mysql_error() function, but it does not return any error string for me. I have
Renaming array keys
The issue: renaming array keys inside a foreach loop.I'm trying to build a pie chart image with the Google Chart API using information from a database. (I'm going to change the type of data I talk
Undefined variables
hi----------------------------------------------------------------------------------------------------error log "[Sat Jan 09 17:40:00 2010] [error] [client 127.0.0.1] PHP Notice: Undefined
mails going in spam??
The mails I sent to folks in my database using mail(function) are going in spam??Any idea how I rectify this issue?
PHP template help
Ok, I don't know if anyone can help me but I am using PHP templates to make a site. I am a newbie and so I am finding this quite difficult so I thought I would ask some folks much better than me. I