Page 1 of 1

Image upload problems

Posted: Thu Sep 21, 2006 5:51 am
by Leao
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

Code: Select all

<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

Code: Select all

<?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.";}}?>

Posted: Thu Sep 21, 2006 7:52 am
by speedy33417
If the site is yours and you want to specifically upload that one image only, I’d just upload the image through FTP, or download CoffeeCup and you could upload that image (or any image) in 5 seconds.
However if it’s for a client, then that’s a different story. I think if you update an image on your server, then a refresh is pretty much mandatory, because your browser will pull that image from your temporary files folder on your own computer, instead of the server.

Hope this helps.

Posted: Thu Sep 21, 2006 8:12 am
by Leao
Hi,

The site is for a client. Is there any way of automatically refreshing a page once?

Thanks,

Leao