Jump to content

passing variables to next page


kev wood

Recommended Posts

i am have created a random number in php and added it an image file so that the image cannot be mistaken for an old image.  i have a image upload on a website and the images that are uploaded are only used for a short time but when the user uploads a new image the old one still displays as it has been cached by the sever, and on the users computer.

 

i now need to pass the random number across to different pages so that it can be added to the image when it is to be displayed so hat the cached version never gets displayed always the new image.

 

what is the best way to pass this information across to the pages get, post or make $rand a global variable.

 

the images are uploaded with a submit button on a form.

Link to comment
https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/
Share on other sites

the echo would print the random number on the screen as i just want to add this number to file for display purposes would the code be something like

 

start_session()
$_session['rand']

 

would this then just make the variable available for use.

i entered that in at the top of the page it worked but it caused errors with other parts of the code.  when the images are resize it didnt like the the variables used in there because of the session start.  why this occurred i dont know as it has nothing to with sessions where the image resize happens.

 

i dont know much about the session start but does it have any effect of the functions i have created as the images resize is done within a function.

Warning: imagesx(): supplied argument is not a valid Image resource in /home/acmeart/public_html/mercury/upload.php on line 61 Warning: imagesy(): supplied argument is not a valid Image resource in /home/acmeart/public_html/mercury/upload.php on line 62 Warning: Division by zero in /home/acmeart/public_html/mercury/upload.php on line 79 Warning: imagecreatetruecolor(): Invalid image dimensions in /home/acmeart/public_html/mercury/upload.php on line 83 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/acmeart/public_html/mercury/upload.php on line 85 Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/acmeart/public_html/mercury/upload.php on line 91 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/acmeart/public_html/mercury/upload.php on line 97 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/acmeart/public_html/mercury/upload.php on line 98

instead of trying to add the random number to the file on the upload could i just add the random number to the image as it is displayed.  this way if it can be done then the images that is cached will always have a random number attached to it. 

all that part of the code is where the original image that is uploaded is resized the actual line reads

 

$old_x=imageSX($src_img);
	$old_y=imageSY($src_img);

 

this error only came up when the session_start() function was added to the top of the page.

here is the section of code it does not like,

 

function make_thumb($img_name,$filename,$new_w,$new_h)
{
	//get image extension.
	$ext=getExtension($img_name);
	//creates the new image using the appropriate function from gd library
	if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
		$src_img=imagecreatefromjpeg($img_name);

  	if(!strcmp("png",$ext))
		$src_img=imagecreatefrompng($img_name);

if(!strcmp("gif",$ext))
	$src_img=imagecreatefromgif($img_name);

	 	//gets the dimmensions of the image
	$old_x=imageSX($src_img);
	$old_y=imageSY($src_img);

	 // next we will calculate the new dimmensions for the thumbnail image
	// the next steps will be taken: 
	// 	1. calculate the ratio by dividing the old dimmensions with the new ones
	//	2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable
	//		and the height will be calculated so the image ratio will not change
	//	3. otherwise we will use the height ratio for the image
	// as a result, only one of the dimmensions will be from the fixed ones
	$ratio1=$old_x/$new_w;
	$ratio2=$old_y/$new_h;
	if($ratio1>$ratio2)	{
		$thumb_w=$new_w;
		$thumb_h=$old_y/$ratio1;
	}
	else	{
		$thumb_h=$new_h;
		$thumb_w=$old_x/$ratio2;
	}

  	// we create a new image with the new dimmensions
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
// resize the big image to the new created one
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 

	// output the created image to the file. Now we will have the thumbnail into the file named by $filename
	if(!strcmp("png",$ext))
		imagepng($dst_img,$filename); 
	else
		imagejpeg($dst_img,$filename);

if (!strcmp("gif",$ext))
	imagegif($dst_img,$filename); 

  	//destroys source and destination images. 
	imagedestroy($dst_img); 
	imagedestroy($src_img); 
}

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.