UPLOAD IMAGES NOT WORKING!


Posted on 16th Feb 2014 07:03 pm by admin

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>&nbsp;</p>
</div>
</div>
</body>
</html>

PLEASE HELP ME

Posted on 25th Jan, 2017
DavidBig
AnabolicsFast Buy Anabolic Steroids Online http://www.anabolicsfast.biz/index.php - AnabolicsFast Buy Anabolic Steroids Online!..

Your Answer:

Login to answer
88 Like 33 Dislike
Previous forums Next forums
Other forums

parsing error
can anyone explain this syntax error:

Parse error: syntax error, unexpected T_IF

The e

Rand() help needed
Hi all,

Can someone explain and give me a quick example of how I would go about this?

Structure Question - One Table or One Table Per Record Set?
I have a web app (mySQL and PHP) which allows people to create an item with up to 200 records which

How would I protect......
I have a from, actually, a good amount of forms. How can I make it so you can't type the characters:

Drop Down and text box issue
Is it possible to set a drop down list and text boxes to a certain width?

here is my code

Retrieving Data from Two Different Databases
Hello All,

Ran into another problem and would appreciate some help! I have two datab

Creation of Raw Exposure manually
SAP Gurus

I am creating Raw Exposure ( Hedge management ) thru T Code TEM10 with followin

database design
Hi,

I got a page which allow candidate to type in their previous working experience,
I let

Product categories for registration
Dear all,

We are going live with the Supplier registered next week. At standard, the 'sel

How to set pass login name from htaccess to php
When the user logs into my members page via htaccess, I'd like to retain the username so that I can

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash