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">&nbsp;</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">&nbsp;</td>
          <td colspan="2" align="center" valign="middle"><input name="submit" type="submit" value="Upload Image" /></td>
        </tr>
        </form>
        <tr>
          <td width="2">&nbsp;</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">&nbsp;</td>
          <td colspan="2" align="center" valign="middle"><?php echo "Medium: <br><img src='gfx/profilephotos/med_".$imagename."'>";  ?></td>
        </tr>
        <tr>
          <td width="2">&nbsp;</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>

    Ok my previous code had a few errors in regarding the sizing but the upload/Ctrl F5 error still persists and for some reason i cant figure it out...

    should i include a delete part where it deletes the previous photo from the server so it can upload the new one?

    i just cant figure out the post/refresh problem... anyone with ideas?

    heres my profilephoto.php

    <?php
    	session_start(); 
    	include("includes/database.php");
    	include('logged2.php');
    	//$_SESSION['nlsession']=true;
    
    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>$height ) {
    									$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>$wih) {
    										$newheight = $largeimage; //sets the longest side for landscape
    										$newwidth = $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 ) {
    										$newheight = $mediumimage; //sets the longest side for landscape
    										$newwidth = $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) ; 
    
    							  if ( $width < 80 and $height < 80 ) {
    									if ( $width > $height ) {
    											$thumbimage=$width;
    										} else { $thumbimage=$height;}
    								} else { $thumbimage=80; } //sets the longest side
    
    							  $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 ) {
    										$newheight = $thumbimage; //sets the longest side for landscape
    										$newwidth = $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);  
    
    
    				  }
    				} //if(isset($_POST['submit'])){
    
    			}
    ?>
    <!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">
    
    </head>
    <body id="HOMEPAGE">
    <div id="wrapper">
      <div id="header">
    
     </div>
      <div id="content"> <img src="gfx/sub_header_profile_picture.jpg" width="610" height="26" />
        <div id="profile">
          <table width="100%" border="0"><br>
          	 <form action="profilephoto.php" method="post" enctype="multipart/form-data" class="uniForm">
    	<tr>
    	<td width="8">&nbsp;</td>
    	<td colspan="2" align="left" valign="middle">
    	<h2><b>Upload your Profile Picture here:</b></h2><br></td>
            </tr>
    
        <tr>
        <td width="8">&nbsp;</td>
        <td colspan="2" align="left" valign="middle"> <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /></td>
        </tr>
    
        <tr>
        <td width="8">&nbsp;</td>
        <td colspan="2" align="left" valign="middle"><input name="submit" type="submit" value="Upload Image" />
    <br><br><hr><br></td>
        </tr>
        </form>
    
    
    <tr>
    <td width="8">&nbsp;</td>
    <td colspan="2" align="left" valign="middle">
    <h2><b>Current Profile Photo:</b></h2><br></td>
        </tr>
    
        <tr>
        <td width="8">&nbsp;</td>
        <td colspan="2" align="left" valign="middle"><?php echo "<img src='gfx/profilephotos/".$imagename."'><br>";  ?></td>
        </tr>
    
    </table>
    
    
    </div>
      </div>
      <div id="sidebar">
        <iframe height="265" width="275" scrolling="no" allowtransparency="true" id="TopFrame" name="TopFrame" frameborder="0" src="userpanel.php"> Your browser does not support iframes. </iframe>
        <br />
    
    <br>
    
      </div>
      <div id="clear"> </div>
      <div id="footer">
    
      </div>
    </div>
    </body>
    </html>
    

      When you say "doesn't upload", are you absolutely positive that the new image isn't uploaded?

      if (isset ($_FILES['new_image'])){
      	$imagename = ("$username"."_".md5($namesurname).".jpg");
      	$source = $_FILES['new_image']['tmp_name']; 
      
      echo "Make certain that there actually is no new image... Source: $source"

      And the reason I doubt it, is that this code always produces the same filename every time, which means that the browser will NOT load it until the old image disappears from the browser's cache.

      $imagename = ("$username"."_".md5($namesurname).".jpg");

      So why not

      $imagename = ("$username"."_".time().".jpg");

      Just don't forget to unlink the old photo if such exists.

        johanafm;10920785 wrote:

        When you say "doesn't upload", are you absolutely positive that the new image isn't uploaded?

        if (isset ($_FILES['new_image'])){
        	$imagename = ("$username"."_".md5($namesurname).".jpg");
        	$source = $_FILES['new_image']['tmp_name']; 
        
        echo "Make certain that there actually is no new image... Source: $source"

        And the reason I doubt it, is that this code always produces the same filename every time, which means that the browser will NOT load it until the old image disappears from the browser's cache.

        $imagename = ("$username"."_".md5($namesurname).".jpg");

        So why not

        $imagename = ("$username"."_".time().".jpg");

        Just don't forget to unlink the old photo if such exists.

        Thanks script works fine with the changes that you suggested!

        Thanks for the tips!

          Write a Reply...