Jump to content

storing images with a random number


kev wood

Recommended Posts

i am having a problem with old images showing up on a web site as they are being displayed from the cache i have tried meta data tags to stop this it didnt work and php headers which also didnt work.  >:(  i am now looking at storing the images with a random number attached to them. 

 

as the number that is attached to them is random when i come to display the image again on a different way what is the best way to get the number across to the next page.  i have tried session_start() but it does not like some of the code in the website and start to throw up loads of errors with code that is working fine without it.

 

if i was to to use a form to post the data should my code look like this

 

code for random number

 

$rand= rand (1, 100);

 

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>

</form>

 

to retrieve value of rand

 

$rand=$_POST['rand']

Link to comment
https://forums.phpfreaks.com/topic/104718-storing-images-with-a-random-number/
Share on other sites

i have changed that code so it looks like what yo have posted put when i try to display the image nothing shows.  so i echoed out the $rand and it gave me no value.  so it is either not passing the data to my send.php page or i am trying to retrieve the data in the wrong way.  i am trying to retrieve the data with

 

$rand=$_POST['rand'];

As i said, is the problem isolated or not?

 

Also, different browsers like to have different 'no-cache' headers. Try this snippet

 

    header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");

sorry dicomatt it took so long to get back i have been working with a group of kids all day trying to get them to design a magazine which was not fun.

 

i have tried those headers and they didnt work.  i put them on every page that had anything to do with the images even if they was not displayed on them and they are still showing the old images.

 

i think the only way i will get this to work is with a random number attached to the image, but that gives me the problem of passing the variable on to that page.  the code just dont like me.

 

i have successfully used the post function before but only to post user names and simple strings around websites i have never used it to pass a random number before.  i thought it would be simple to code but oh how i was wrong.  either that or i have forgotten how it is done and i am just messing it up with the code.  the code i am using looks like this

 

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

</form>

 

and to retrieve the variable on the next page i have tried writing this code both ways

 

$_POST['rand']=$rand;

 

$rand=$_POST['rand'];

 

still with no joy

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.