i have created a website where the user is able to upload images and then they are displayed on and email which is then sent out to the people of there choice.

the problem i am getting is that the images are being cached and then the new images are not displaying.

i have used if file exist to display the images on the email and also used it to unlink the files once they have been used. When the user comes to use the system next time if they upload an image of the same file type then it is displaying the cached version and not the new image. if a image with a different file type is uploaded then it works, but this will only show different images as long as the file type has not been used.

i have tried using this

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">

which has had no effect on the situation. i put the above code inside the head tag is this the correct place to put it. the reason i put it there is because this is usually were the meta tags are placed.

Recommended Answers

All 10 Replies

Yep ! <head> tag is the right place to put meta tags. I haven't come across caching problem, but maybe you can use this.

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

Source: http://nl2.php.net/header Ex. 2

i have tried that and had no joy. i checked on the server to see if it was a problem with the unlink code i have but it is defiantly uploading the images and removing the old files on the server. I know this as the time stamps for when the file was uploaded are changing.

i will have a good search around the web and see what i can find i will post it here if i find anything that works.

Hey, If you don't have any "processing" in your script, why not redirect the script to the same page ? Will it still have the images in the cache ?

the images are being cached on the server i think and this why the same images show up on the emails i think. i am working on adding a random number to the image when it is uploaded and then using the post/get method to retrieve the value of the random number to use to display the image.

if a random number is added to the image then the image that is shown on the email page will always have a different value added to it so it should always show the new images that are uploaded.

well that is the theory behind it anyway weather it works or not is another thing.

is it possible to a random number to a image file without it becoming a part of that file name. what i want to do is where i am displaying the image add a random number so that the image when cached has this number attached to it but it is not part of the path to the file.

so i want it to be displayed by getting the file name then adding the number so that the number changes every time the page is viewed and the image cannot be displayed from the cach

is it possible to a random number to a image file without it becoming a part of that file name.

No.. You can rename a file by concating a random number. You cant add random number to an image without changing its name..

so would it be possible use the if file exists to retrieve the file and then on each individual page add a unique random number to each image so that they all have there own number attached to them.

I don't know what you mean by that.. But, if you use "if file exists" and add a random number to the image, What is the point in storing the filename in the table ?

i am storing the files on the server so that they can be recalled when the email is sent out with the images held within it. the reason i want to add the random number after they have been stored is because the images are being cached.

the problem with the images getting cached is if the user comes and uploads a new image with the same file extension it will only show the cached version of the image. i have tried to stop the images getting cached with various different methods which in clude php headers and html meta tags, both methods failed.

so my next attempt at trying to get it show the new images is by adding a random number. if i store the number with the file i have no way of knowing the full path to the file once a random number has been added to it.

i tried a method were the random number that was generated was sent to the other pages with the session_start() function but that through up a load of errors with my code that is working fine without that in.

if i can get it to find the image without the random number attached to it then add this i am hoping this will stop the old images from being displayed on the pages. I know it is a problem with the images being cached because each time the upload page is entered it unlinks the last file that was uploaded.

hope that makes it a bit more clear.

if i am to store the image with a random number attached to it then could i post the number on the submit button and retrieve it on the next page. would the code look something like this

$rand= rand(1, 100);

to display the image on the upload page

$thumb_name=$broad1name2 . $rand;

to post the random number to the next page on the submit button

<form name="newad" method="post" enctype="multipart/form-data"  action="">
		<input type="hidden" method="post" name="rand" />
		<input type="file" name="broad1_image"  ></td></tr>
		<input name="Submit" type="submit" id="image1" value="Upload image" ></td></tr>

and to retrieve the random number on the next page


that way the number would be the same if the code is correct

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.