Jump to content

IE refreshing of images that don't exist


gsaldutti

Recommended Posts

This isn't completely a PHP question, but you guys are geniuses so I figured I'd ask and see if any of you knew...

 

I have a PHP page that has several forms on it that upload images to my server.  The action of all forms is to reload the same page the forms are on.  As soon as the images are uploaded, the images appear on the user's browser  (It's a simple script to put the image into a folder on my server and a simple echo of the file name to display it).  This part works fine on both IE and Firefox.

 

However, I have a "remove image" script as well and on IE only, when the user clicks "Remove image", the image is completely removed from my server fine (i.e. it truly no longer exists on my server), but the image still shows in the IE browser (Firefox works fine, meaning as soon as the user clicks "Remove image", the image disappears completely, as it should since it no longer exists on my server).

 

If the IE user refreshes the page, then the image finally goes away, but I can't expect them do that.  Is there a way to make IE work just like Firefox in respect to images disappearing if they truly don't exist, or is there some way to make a page refresh itself immediately after the page reloads with PHP?

 

It just seems ridiculous that IE continues to display an image that no longer exists. 

 

Any thoughts would be appreciated greatly.

 

Thank you...

 

Link to comment
Share on other sites

Sure, my code is below. FYI, I'm VERY new to PHP so I'm sure my code is not even close to being as efficient as it can be, so don't laugh too hard  :)....

 

First, this is what my image upload form looks like...

 


<!-- START Upload Form #1------------------------------------------->

<tr>
<td  width=300 height=200>
<?php
if ($isfile1=="yes") {
?>
<form action="fillscript.php" method="POST">
<input type="submit" name="submit" value="Remove Image 1">
(So you can add a different image)
</form>

<?php
} else {
?>
<form action="fillscript.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">  Upload Image: <input type="file" name="userfile" >
<font size="1">Click browse to upload a file</font>
<input type="submit" name="submit" value="Upload Image 1">
</form> 

<?php
}
?>
</td>
<td  width=400 height=200><img src="http://localhost/pas/upload/<?php echo $file1name; ?>" />
</td>
</tr>

<!-- END Upload Form #1------------------------------------------>


 

 

And here is the code that removes the image when they click the "Remove Image 1" button above...

 


if (isset($_POST['submit']) && $_POST['submit'] == "Remove Image 1" ) { 



		//to delete image from the UPLOAD folder

		$removeimage = unlink("upload/$file1name");
		if($removeimage) {
			$removemessage = "Actual Image was deleted from UPLOAD folder";
			$isfile1="no";
		} else {
			$removemessage = "Actual Image was NOT deleted!";
		}


} 

Link to comment
Share on other sites

Hey Genericnumber1,

 

Do I just put that header at the top of the page, or does it need to go in the script that removes the actual image from my server?

 

That's kind of rhetorical because I actually tried it in both spots and neither worked. 

 

What's even weirder that I forgot to mention is that in IE, I upload an image (we'll call it IMAGE-A) and then I hit "Remove Image" and IMAGE-A is removed from the server but it still shows in the browser.  THEN, I upload another different image (we'll call it IMAGE-B) and it STILL SHOWS IMAGE-A in the browser, even though the only image on my server is IMAGE-B. I just don't get it. Makes no sense.

 

Anyway, can you elaborate a bit on that "sleep" thing you mentioned? I've never heard of that but I'm willing to try anything.

Link to comment
Share on other sites

That one didn't work either.  Is there some way to test that the cache is not being used (i.e. to test that your header is doing it's job)?  I totally trust that it should be doing what you say, but if I can confirm that it's not using the cache, then I'll know there must be something else in my code causing the issue. 

 

But like you said, it sounds like it's gotta be the cache causing the problem.

 

I wish there was some PHP code that would recognize if someone was using IE and automatically close their IE, automatically install Firefox on their machine, and automatically re-open my site in Firefox  ;)

Link to comment
Share on other sites

Still no luck.  MAN I HATE IE.  I guess I'll have to submit all my upload-image forms to a different page and then redirect back (like dropfaiths) but I don't know if that is feasible with the way I want the site to work.  Guess the only way I'll know is to try it.  :)

 

Hey Dropfaith, does your "other page" ever display in the user's browser, or does it simply process data and ALWAYS redirect back to the original page?

 

I am using SESSIONS by the way, not sure if that matters

Link to comment
Share on other sites

its ugly but  im working on alot of my scripts for this site still

 

my example of my page that deletes it never displays anything to the user just deletes and redirects

<?php
session_start( ); //bored of this function yet?
if(!isset($_SESSION["username"])){
header('Location: /user/index.php');
}
else
{
header('Location: /user/index.php');
?>

<?
// includes
include("../header.php");


// open database connection
$conn = mysql_connect(HOST, DBUSER, PASS) or  die('Could not connect !<br />Please contact the site\'s administrator.');
$db = mysql_select_db(DB) or  die('Could not connect to database !<br />Please contact the site\'s administrator.');

// connects to db above
$Id = mysql_escape_string(trim(htmlentities($_GET['Id'])));	
$result = mysql_query("SELECT * FROM Artistimages WHERE Id='$Id'") 
or die(mysql_error()); 
$row = mysql_fetch_object($result);

      $destination = '/home/www/lawrenceguide.org/www/art/';
      $uploaded = $row->uploaded; //assume that this is the image_name field from your database
      //unlink function return bool so you can use it as conditon
      if(unlink($destination.$uploaded)){
      }
$query = mysql_query("DELETE FROM Artistimages WHERE Id='$Id'") 
or die(mysql_error()); 
?>
<?php
}
?>

Link to comment
Share on other sites

FYI, I created a new, separate page called "deleteimage.php" which does nothing but delete the image from my server and redirect back to the main page and it STILL will not work.  The old images that are nowhere to be found on my server still display in the IE browser.  Unbelievable.

 

Anyway, thanks for all your help up to this point.

 

 

Link to comment
Share on other sites

I hope it's that easy of a solution.  Anyway, I uploaded my stuff to http://gdoot.com/imagetest/uploadimage.php but when I try to upload, naturally I get an error:

 

Fatal error: Call to undefined function imagecreatefromjpeg() in /home/gdootcom/public_html/imagetest/uploadimage.php on line 50

 

I think that means my server doesn't have a certain image library or something, right?  That could be a problem (unless it's easy to get it installed on the server).

 

Any thoughts?

 

***Disregard the stuff above the Table.  That's just testing stuff for my own reference

Link to comment
Share on other sites

I think that GD library thing is NOT enabled on my server, so I think I gotta figure out how to get that enabled (I made the entire PHPINFO show on that link I gave you earlier and I don't see "GD" anywhere). 

 

Anyway, here is the entire file (I tried to take out all the repetitive stuff to make it easier to browse through).  Again, this is the only file and the action of the upload form is the page itself....

 


<?php header("Cache-Control: no-cache, must-revalidate"); 
require_once("includes/session.php");
require_once("includes/connection.php");


$success="";
$message="";
$badinsert="";
$deletemessage="";
$imagemessage="";
$removemessage="";

$wrongfiletype1="";
$nofilechosen1="";

$sessionid = session_id();

$file1name = "0-" . $sessionid . ".jpg";


if (isset($_POST['submit']) && $_POST['submit'] == "Upload Image 1") { 

					if ($_FILES['userfile']['type'] == "image/pjpeg" || $_FILES['userfile']['type'] == "image/jpeg" ) {


										// This is the temporary file created by PHP 
										$uploadedfile = $_FILES['userfile']['tmp_name'];

										// Create an Image from it so we can do the resize
										$src = imagecreatefromjpeg($uploadedfile);

										// Capture the original size of the uploaded image
										list($width,$height) = getimagesize($uploadedfile);

										// For our purposes, I have resized the image to be
										// 600 pixels wide, and maintain the original aspect 
										// ratio. This prevents the image from being "stretched"
										// or "squashed". If you prefer some max width other than
										// 600, simply change the $newwidth variable
										$newheight=200;
										$newwidth=($width/$height)*200;
										$tmp=imagecreatetruecolor($newwidth,$newheight);

										// this line actually does the image resizing, copying from the original
										// image into the $tmp image
										imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 

										// now write the resized image to disk. I have assumed that you want the
										// resized, uploaded image file to reside in the ./images subdirectory.
										$imagefolder = "upload/0-". $sessionid . ".jpg";
										if (imagejpeg($tmp,$imagefolder,100)) {
											$imagemessage = "File is valid, and was successfully uploaded into FOLDER.\n";
											$success="yes";
											} else {
											$imagemessage = "Possible file upload attack!\n";
											$success="no";
											}
										imagedestroy($src);
										imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
										// has completed.



				$isfile1 = "yes";



				$filesize = $_FILES['userfile']['size'];	


				} elseif ($_FILES['userfile']['type'] == "") {
					$nofilechosen1 = "You did not select a file";	


				} else {
					$wrongfiletype1 = "This image is not a JPEG image!!!!!!!!!";
				}	



	if($success=="yes"){
			$query = "INSERT INTO images (
					name, size
				) VALUES ('" . $file1name . "','" . $filesize . "')";

			$result = mysql_query($query, $connection);
					if ($result) {
						$message = "<p>The image was successfully submitted into the DATABASE.  </p>";

					} else {
						$message = "The image was NOT submitted.";
						$message .= "<br />" . mysql_error();


					}
		}
		else {
			$badinsert = "<p>Didnt work!</p>";
		}




} else {

}



if (isset($_POST['submit']) && $_POST['submit'] == "Remove Image 1" ) { 



		//need to delete image from the UPLOAD folder

		$removeimage = unlink("upload/$file1name");
		if($removeimage) {
			$removemessage = "Actual Image was deleted from UPLOAD folder";
			$isfile1="no";
		} else {
			$removemessage = "Actual Image was NOT deleted!";
		}

		//need to delete image info from the DATABASE

		$query = "DELETE FROM images 
					WHERE name = '$file1name'";

						$result = mysql_query($query, $connection);
								if ($result) {
									$deletemessage = "<p>The image was successfully DELETED.  </p>";

								} else {
									$deletemessage = "The image was NOT deleted.";
									$deletemessage .= "<br />" . mysql_error();


								}
} else {

}


if (file_exists("upload/$file1name")){
$isfile1 = "yes";
} else {
$isfile1 = "no";
}
?>

<html>

<head>
<meta http-equiv="pragma" content="no-cache" />
    <title>Fill Script</title>
<link href="smile.css" type="text/css" rel="stylesheet">


</head>

<body>

<div id="entirepage">
<?php


echo $sessionid;
echo "SUCCESS=" . $success;
echo $imagemessage;
echo $message;
echo $badinsert;

echo $deletemessage;
echo $removemessage;



echo "File 1 =" . $isfile1 . "<br>";

?>
<table WIDTH="980" CELLPADDING=5 CELLSPACING=5 BORDER=1 ALIGN=left>

<tr >
<td colspan=3>blah blah blah
</td>
</tr>

<!-- START Upload Form #1------------------------------------------->

<tr>
<td  width=300 height=200>
<?php
if ($isfile1=="yes") {
?>
<form action="uploadimage.php" method="POST">
<input type="submit" name="submit" value="Remove Image 1">
(So you can add a different image)
</form>

<?php
} else {
?>
<form action="uploadimage.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">  Upload Image: <input type="file" name="userfile" >
<font size="1">Click browse to upload a file</font>
<input type="submit" name="submit" value="Upload Image 1">
</form> 


<?php
echo "<span class='error'>" . $nofilechosen1 . "</span>";
echo "<span class='error'>" . $wrongfiletype1 . "</span>";
}
?>
</td>
<td  width=400 height=200><img src="http://localhost/pas/upload/<?php echo $file1name; ?>" />
</td>
</tr>

<!-- END Upload Form #1------------------------------------------>




</table>


<?php
phpinfo();
?>
</div>
</body>
</html>
<?php

require_once("includes/footer.php");
?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.