kev wood Posted May 8, 2008 Share Posted May 8, 2008 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 More sharing options...
conker87 Posted May 8, 2008 Share Posted May 8, 2008 Sessions. Page 1: <?php session_start(); $rand = rand(); $_SESSION['rand'] = $rand; ?> Page 2: <?php session_start(); echo $_SESSION['rand']; ?> Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535788 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535793 Share on other sites More sharing options...
conker87 Posted May 8, 2008 Share Posted May 8, 2008 Adding session_start() to the top of the page will start the session and allow for the session variable to be passed. As long as you have that function there. Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535796 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535804 Share on other sites More sharing options...
moon 111 Posted May 8, 2008 Share Posted May 8, 2008 start_session(); $_session['rand']; You forgot the semi-colons Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535805 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 no the i left the semi colons off in that post because i am lazy bast**d they were in when i put the code on to the pages i had also put start ans session the wrong way round. Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535808 Share on other sites More sharing options...
conker87 Posted May 8, 2008 Share Posted May 8, 2008 Can you post the errors? Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535819 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 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 Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535822 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 the problem starts here: Warning: imagesx(): supplied argument is not a valid Image resource in /home/acmeart/public_html/mercury/upload.php on line 61 what is line 61? Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535880 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535881 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535898 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 what is $src_img? apparently, it isn't a valid image resource. it would be much easier to help if we could see all of the code. Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535900 Share on other sites More sharing options...
kev wood Posted May 8, 2008 Author Share Posted May 8, 2008 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); } Link to comment https://forums.phpfreaks.com/topic/104691-passing-variables-to-next-page/#findComment-535916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.