This is a discussion on calling a php script using img src ="random.php" within the PHP Language forums, part of the PHP Programming Forums category; Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey all,
I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to call that in another page so that i get a random image the page is http://2006ymcanationals.com/index.php using <img src="random.php"> It is not working. I have tried using the full path to the "random.php". I have also tried naming the main page index.html and index.php. neither work. what am i missing? Searching these groups it looks like this should work. Thanks in advance. Brad |
|
|||
|
<bhennon@gmail.com> wrote in message news:1111008806.788804.63370@l41g2000cwc.googlegro ups.com... > Hey all, > > I have a small php script that calls a random image at the following > page. > http://www.2006ymcanationals.com/random.php > > IT WORKS IF I go directly to the above link. > > I am trying to call that in another page so that i get a random image > the page is http://2006ymcanationals.com/index.php using <img > src="random.php"> > > It is not working. I have tried using the full path to the > "random.php". I have also tried naming the main page index.html and > index.php. neither work. > > what am i missing? Searching these groups it looks like this should > work. > > Thanks in advance. > > Brad It's hard without looking at the code. The images seem to be different names on the page. Eg. rimage2.jpg, rimage3.jpg, rimage4.jpg, rimage5.jpg Brent Palmer. |
|
|||
|
bhennon@gmail.com wrote:
> > I have a small php script that calls a random image > at the following page. > http://www.2006ymcanationals.com/random.php > > IT WORKS IF I go directly to the above link. > > I am trying to call that in another page so that i get > a random image the page is http://2006ymcanationals.com/index.php > using <img src="random.php"> Actually, in your index.php page, it's not <img src="random.php">, it's <img href="random.php">. Correct it, and everything should work... Cheers, NC |
|
|||
|
bhennon@gmail.com wrote:
> IT WORKS IF I go directly to the above link. > > I am trying to call that in another page so that i get a random > image > > It is not working. > > what am i missing? Searching these groups it looks like this should > work. You're outputting HTML from your PHP-script, not the image itself. It's the same as if you try to have <IMG SRC="whatever.html"> - I don't think you suppose that to work (unless whatever.html actually is a very strangely named image file, of course). What you should be doing in your script is to output suitable headers for the image, and pass the image through your script. Something like this: <?php $img_filename = 'test.gif'; // On serverside // The above is what you can take as random... header('Content-type: image/gif'); // header('Content-type: '.mime_content_type($img_filename)); // Use this if your server supports it! header('Content-length: '.filesize($img_filename)); $file_pointer = fopen($img_filename, 'rb'); fpassthru($file_pointer); fclose($file_pointer); exit; ?> -- Markku Uttula |
|
|||
|
*** bhennon@gmail.com escribió/wrote (16 Mar 2005 13:33:26 -0800):
> http://www.2006ymcanationals.com/random.php > > IT WORKS IF I go directly to the above link. > > I am trying to call that in another page so that i get a random image > the page is http://2006ymcanationals.com/index.php using <img > src="random.php"> Your script does not return an image. It returns an HTML page that links to an image. You cannot link to an HTML page with the <img> tag. Maybe you're thinking of <iframe>? You could either choose a random filename: <img src="<?=get_random_img_name()?>"> Or make your script return an actual image: <? header('Content-Type: image/gif'); readfile('foo.gif'); ?> -- -+ Álvaro G. Vicario - Burgos, Spain +- http://www.demogracia.com (la web de humor barnizada para la intemperie) ++ No envíes tu dudas a mi correo, publícalas en el grupo -+ Do not send me your questions, post them to the group -- |
|
|||
|
Thanks for all your help.
I dont know php well enough to write this stuff. I am following instructions found here: http://www.gatequest.net/misc/php/random-image.php will this work? Alvaro G. Vicario wrote: > *** bhennon@gmail.com escribió/wrote (16 Mar 2005 13:33:26 -0800): > > http://www.2006ymcanationals.com/random.php > > > > IT WORKS IF I go directly to the above link. > > > > I am trying to call that in another page so that i get a random image > > the page is http://2006ymcanationals.com/index.php using <img > > src="random.php"> > > Your script does not return an image. It returns an HTML page that links to > an image. You cannot link to an HTML page with the <img> tag. Maybe you're > thinking of <iframe>? > > You could either choose a random filename: > > <img src="<?=get_random_img_name()?>"> > > Or make your script return an actual image: > > <? > header('Content-Type: image/gif'); > readfile('foo.gif'); > ?> > > -- > -+ Álvaro G. Vicario - Burgos, Spain > +- http://www.demogracia.com (la web de humor barnizada para la intemperie) > ++ No envíes tu dudas a mi correo, publícalas en el grupo > -+ Do not send me your questions, post them to the group > -- |
|
|||
|
<bhennon@gmail.com> wrote in message news:1111022218.387067.58250@l41g2000cwc.googlegro ups.com... Thanks for all your help. I dont know php well enough to write this stuff. I am following instructions found here: http://www.gatequest.net/misc/php/random-image.php will this work? Yes this works fine for me. As I said the images seem to be displaying with different names which indicate to me that all is working. What images do you have in the folder? Do they look the same? Brent Palmer. |
|
|||
|
*** bhennon@gmail.com escribió/wrote (16 Mar 2005 17:16:58 -0800):
> I dont know php well enough to write this stuff. I am following > instructions found here: > http://www.gatequest.net/misc/php/random-image.php > > will this work? It should, given that you link to that script from the <img> tag. -- -+ Álvaro G. Vicario - Burgos, Spain +- http://www.demogracia.com (la web de humor barnizada para la intemperie) ++ No envíes tu dudas a mi correo, publícalas en el grupo -+ Do not send me your questions, post them to the group -- |
|
|||
|
On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
made "Alvaro G. Vicario" <kAlvaroNOSPAMTHANKS@terra.es> write: >*** bhennon@gmail.com escribió/wrote (16 Mar 2005 13:33:26 -0800): >> http://www.2006ymcanationals.com/random.php >> >> IT WORKS IF I go directly to the above link. >> >> I am trying to call that in another page so that i get a random image >> the page is http://2006ymcanationals.com/index.php using <img >> src="random.php"> > >Your script does not return an image. It returns an HTML page that links to >an image. You cannot link to an HTML page with the <img> tag. Maybe you're >thinking of <iframe>? > >You could either choose a random filename: > ><img src="<?=get_random_img_name()?>"> > >Or make your script return an actual image: > ><? >header('Content-Type: image/gif'); >readfile('foo.gif'); >?> You know... I'm experiencing a very similar issue. In my case, I am building a counter script (* non-relevant reasons below) and I have similar behavior. I call the script directly in its own directory and it outputs the composite image fine. Calling it from one directory higher from within an HTML file gives a broken image. Originally, I copied from another script that output multiple individual gifs when the script was called. I never understood how that was supposed to work, other than as a stand-alone script, so I redid the code to copy each image jpg into one image that I output from the script. Relevant code: <<< //determine size of images in directory by testing the zero image $source = $style_folder . "0." . $ext; $img_size = @getimagesize( $source ); // $width is string length in characters $dst_img=ImageCreate( $width * $img_size[0], $img_size[1] ); for ($i=0;$i<strlen($countstring);$i++) { $digit=substr("$countstring",$i,1); // Build the image URL ... $source = $style_folder . $digit . "." . $ext; $src_img = imagecreatefromjpeg( $source ); // $source = $base_url . $style_folder . $digit . "." . $ext; // echo "<img src=\"$source\" border=0>"; imagecopy( $dst_img, $src_img, $i * $img_size[0], 0, 0, 0, $img_size[0], $img_size[1]); } header( "Content-type: image/jpeg" ); ImageJpeg($dst_img); exit(); <<< And from the calling HTML: <<< <img src="_Counters/jpbcount.php?link=Tester&style=odometer" height="20" align="ABSMIDDLE"> <<< I've tried calling the script with both an <img src= and <img href= to no avail. Any pointers? Thanks. -JPB *Non-relevant rationale I may be migrating my server over to a Linux-based hosting service from my own Windows 2000-based server. I liberally used a CGI program on my site and now that I may be going to a Linux-based system, I figured I'd mimic the functionality of it in a more portable PHP script. |
|
|||
|
"Dahak" <Dahak_II@thefifthimperium.com> wrote in message news:pf8051td36s9ia5eqbl1c1bsgsj81iev74@4ax.com... > On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser > made "Alvaro G. Vicario" <kAlvaroNOSPAMTHANKS@terra.es> write: > > >*** bhennon@gmail.com escribió/wrote (16 Mar 2005 13:33:26 -0800): > >> http://www.2006ymcanationals.com/random.php > >> > >> IT WORKS IF I go directly to the above link. > >> > >> I am trying to call that in another page so that i get a random image > >> the page is http://2006ymcanationals.com/index.php using <img > >> src="random.php"> > > > >Your script does not return an image. It returns an HTML page that links to > >an image. You cannot link to an HTML page with the <img> tag. Maybe you're > >thinking of <iframe>? > > > >You could either choose a random filename: > > > ><img src="<?=get_random_img_name()?>"> > > > >Or make your script return an actual image: > > Here's a working example that might help. This checks to see if a website is up and if it is, it displays a smiley gif and if not, a not so smiley gif in a table of smileys. Now the page doesn't wait for ALL the smileys to not time out before displaying; rather it displays the whole table immediately and these pop up as they finish running. Now if it would only display a "processing" gif while we waited :>) ==== An Actual Table Row ====== <tr> <td>Logon.net</td> <th><img src="/frag/status.php?addr=www.logon.net" width="37" height="20"></th> <th><img src="/frag/status.php?addr=mail.logon.net&port=25" width="37" height="20"></th> <th><img src="/frag/status.php?addr=mail.logon.net&port=110" width="37" height="20"></th> <th><img src="/frag/status.php?addr=mail.logon.net" width="37" height="20"></th> <th> </th> </tr> ==== status.php has to be above Doc Root =============== <?php //Web Server Status v 1.2, Copyright 2002 By Ryan Schwiebert, visit http://www.schwebdesigns.com/ //This script may be freely distributed providing all copyright headers are kept intact. //Concept from: //Abax Server Status v1.04, Copyright 2002 By Nathan Dickman, visit http://www.NathanDickman.com/ //Location of the live or dead server images // Updated by John Jarrett 2003 //Please change to your server specifications $live = "/frag/images/live2.gif"; $dead = "/frag/images/dead2.gif"; //The status checking script //meddle at your own risk! //check for port number, default is 80 #list($addr,$port)= explode (':',"$link"); if (empty($port)) { $port = 80; } //Test the server connection $churl = @fsockopen(server($addr), $port, $errno, $errstr, 20); #$churl = @fsockopen($addr, $port, $errno, $errstr, 20); if (!$churl){ header("Location: $dead"); } else { header("Location: $live"); } function server($addr){ if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));} return $addr; } ?> ====== end of script ===== hth, John |