Hi,
I've got a form with an image above it that allows me to upload a new image via PHP (see attached code). I select a new image from my comp and then submit the image to a PHP page that checks to see if the image is the right dimensions/type/size before uploading it onto the server at images/amazingloveb.jpg, overwriting the previous file. The PHP then redirects me to the original page where I should be able to see my new uploaded image.
The process works but is unreliable. Most of the time after I'm redirected to the original page, I need to click 'Refresh' a couple of times on my browser before I can see the new image. Other times I have to wait a few minutes before the image changes no matter how many times I click 'Refresh'. Other times the image doesn't change at all and further still sometimes the PHP deletes the old image but fails to upload anything.
I understand it would be much better to give the uploaded image a new path rather than overwriting the old one but I need to keep the path images/amazingloveb.jpg as I have a Flash site that is trying to retrieve images from that specific location.
Do you have any ideas for making the process more reliable?
Many, many thanks,
leo
amazinglove.php
<div align="center">
<p><img src="images/amazingloveb.jpg" alt="amazinglove" width="530" height="170"></p>
<p>
<form enctype="multipart/form-data" action="amazinglovephoto.php" method="POST">
<p>
<input name="uploaded" type="file" size="35" />
<br>
<br/>
<input type="submit" value="change photo (530 x 170 pixels)" />
</p>
</form></div>
amazinglovephoto.php
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']);
$ok=1;
list($ImportWidth,$ImportHeight,$ImportMimeType) = getimagesize($_FILES['uploaded']['tmp_name']) ;
if ($ImportWidth != 530)
{header("Location: 530170error.php");
$ok=0;}
if ($ImportHeight != 170)
{header("Location: 530170error.php");
$ok=0;}
if ($ImportMimeType != 2)
{header("Location: jpegerror.php");
$ok=0;}
if ($uploaded_size > 70000)
{header("Location: sizeerror.php");
$ok=0;}
if ($ok==0)
{echo "Sorry your file was not uploaded";}
else
{if(move_uploaded_file($_FILES['uploaded']['tmp_name'], 'images/amazingloveb.jpg'))
{header("Location: amazingloveupload.php");}
else
{echo "Sorry, there was a problem uploading your file.";}}?>