Hey Guys....
i have an irritating glitch on my page the i'm not able to find or work out why its doing it...
if its a new profile and you upload an image it uploads with no problems at the beginning but as soon as you upload a second photo to replace the 1st photo it doesnt upload it it doesnt matter how much you try it wont upload the next photo.
But it you did try uploading a photo that didnt upload and you then press CTRL F5 to do a complete refresh of the page it uploads like a charm!
can any one point me in the right direction? heres my code....
<?php
session_start();
include("includes/database.php");
include('logged2.php');
if ( $_SESSION['nlsession'] <> true ) {
header("location: /alphaVer3/");
} else {
$user=$_SESSION['nlemail'];
$pass=$_SESSION['nlpassword'];
$token=$_SESSION['nltoken'];
$query=("select * from useraccounts where email='$user' and password='$pass' and token='$token';");
$results=mysql_query($query);
$userinfo=mysql_fetch_array($results);
$username=$userinfo['username'];
$namesurname=("$userinfo[name] $userinfo[surname]");
$imagename = $userinfo['profilephoto'];
if(isset($_POST['submit'])){ //if(isset($_POST['submit'])){
if (isset ($_FILES['new_image'])){
$imagename = ("$username"."_".md5($namesurname).".jpg");
$source = $_FILES['new_image']['tmp_name'];
$target = "gfx/profilephotos/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "gfx/profilephotos/" . $imagepath; //This is the new file you saving
$file = "gfx/profilephotos/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
if( $width < 500 and $height < 500 ){
if ($width >= $height ) {
$largeimage=$width;
} else { $largeimage=$height; }
} else {
$largeimage=500; } //sets the longest side
$imgratio=$width/$height; //works out the image ratio and if its a portrait or landscape
if ($imgratio>1){ //tests if it is a landscape
if ( $width>$largeimage ) {
$newwidth = $largeimage; //sets the longest side for landscape
$newheight = $largeimage/$imgratio; //calculate the shortest side for landscape
} else { $newwidth = $width; //sets the longest side for landscape
$newheight = $height; //calculate the shortest side for landscape
}
}else{
if ( $height>$largeimage ) {
$newwidth = $largeimage; //sets the longest side for landscape
$newheight = $largeimage/$imgratio; //calculate the shortest side for landscape
} else { $newwidth = $width; //sets the longest side for landscape
$newheight = $height; //calculate the shortest side for landscape
}
}
$tn = imagecreatetruecolor($newwidth, $newheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "gfx/profilephotos/med_" . $imagepath; //This is the new file you saving
$file = "gfx/profilephotos/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
if( $width < 195 and $height < 195 ){
if ($width >= $height ) {
$mediumimage=$width;
} else { $mediumimage=$height; }
} else {
$mediumimage=195; } //sets the longest side
$imgratio=$width/$height;
if ($imgratio>1){ //tests if it is a landscape
if ( $width>$mediumimage ) {
$newwidth = $mediumimage; //sets the longest side for landscape
$newheight = $mediumimage/$imgratio; //calculate the shortest side for landscape
} else { $newwidth = $width; //sets the longest side for landscape
$newheight = $height; //calculate the shortest side for landscape
}
}else{
if ( $height>$mediumimage ) {
$newwidth = $mediumimage; //sets the longest side for landscape
$newheight = $mediumimage/$imgratio; //calculate the shortest side for landscape
} else { $newwidth = $width; //sets the longest side for landscape
$newheight = $height; //calculate the shortest side for landscape
}
}
$tn = imagecreatetruecolor($newwidth, $newheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "gfx/profilephotos/thumb_" . $imagepath; //This is the new file you saving
$file = "gfx/profilephotos/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$thumbimage=80;
$imgratio=$width/$height;
if ($imgratio>1){ //tests if it is a landscape
if ( $width>$thumbimage ) {
$newwidth = $thumbimage; //sets the longest side for landscape
$newheight = $thumbimage/$imgratio; //calculate the shortest side for landscape
} else { $newwidth = $width; //sets the longest side for landscape
$newheight = $height; //calculate the shortest side for landscape
}
}else{
if ( $height>$thumbimage ) {
$newwidth = $thumbimage; //sets the longest side for landscape
$newheight = $thumbimage/$imgratio; //calculate the shortest side for landscape
} else { $newwidth = $width; //sets the longest side for landscape
$newheight = $height; //calculate the shortest side for landscape
}
}
$tn = imagecreatetruecolor($newwidth, $newheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$updatepass=("update useraccounts set profilephoto='$imagepath' where email='$user' and password='$pass' and token='$token';");
mysql_query($updatepass);
}
}
}
?>
<!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" />
<meta http-equiv="cache-control" content="no-cache" />
<META NAME="Pragma" CONTENT="no-cache">
<meta name="robots" content="index" />
<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="en,za">
<META NAME="Expires" CONTENT="0">
<META NAME="DESCRIPTION" CONTENT="...summary of web page...">
<title>www.site.co.za -<?php echo("$userinfo[name] $userinfo[surname]'s Nightlife profile"); ?></title>
<link href="css/ANstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
</div>
<div id="content"> <img src="gfx/welcome.jpg" width="610" height="36" />
<div id="profile">
<table width="100%">
<form action="profilephoto.php" method="post" enctype="multipart/form-data" class="uniForm">
<tr>
<td width="2"> </td>
<td colspan="2" align="center" valign="middle"> <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /></td>
</tr>
<tr>
<td width="2"> </td>
<td colspan="2" align="center" valign="middle"><input name="submit" type="submit" value="Upload Image" /></td>
</tr>
</form>
<tr>
<td width="2"> </td>
<td colspan="2" align="center" valign="middle"><?php echo "Large image: <br><img src='gfx/profilephotos/".$imagename."'><br>"; ?></td>
</tr>
<tr>
<td width="2"> </td>
<td colspan="2" align="center" valign="middle"><?php echo "Medium: <br><img src='gfx/profilephotos/med_".$imagename."'>"; ?></td>
</tr>
<tr>
<td width="2"> </td>
<td colspan="2" align="center" valign="middle"><?php echo "Thumbnail: <br><img src='gfx/profilephotos/thumb_".$imagename."'>"; ?></td>
</tr>
</table>
</div>
</div>
<div id="sidebar">
</div>
<div id="clear"> </div>
<div id="footer">
</div>
</div>
</body>
</html>