calling a php script using img src ="random.php"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bhennon@gmail.com

    calling a php script using img src ="random.php"

    Hey all,

    I have a small php script that calls a random image at the following
    page.


    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

  • Brent Palmer

    #2
    Re: calling a php script using img src =&quot;random.p hp&quot;


    <bhennon@gmail. com> wrote in message
    news:1111008806 .788804.63370@l 41g2000cwc.goog legroups.com...[color=blue]
    > 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[/color]

    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.




    Comment

    • NC

      #3
      Re: calling a php script using img src =&quot;random.p hp&quot;

      bhennon@gmail.c om wrote:[color=blue]
      >
      > 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 ">[/color]

      Actually, in your index.php page, it's not <img src="random.php ">,
      it's <img href="random.ph p">. Correct it, and everything should
      work...

      Cheers,
      NC

      Comment

      • Markku Uttula

        #4
        Re: calling a php script using img src =&quot;random.p hp&quot;

        bhennon@gmail.c om wrote:[color=blue]
        > 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.[/color]

        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.h tml"> - 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_filen ame));
        // Use this if your server supports it!
        header('Content-length: '.filesize($img _filename));
        $file_pointer = fopen($img_file name, 'rb');
        fpassthru($file _pointer);
        fclose($file_po inter);
        exit;
        ?>

        --
        Markku Uttula

        Comment

        • Alvaro G. Vicario

          #5
          Re: calling a php script using img src =&quot;random.p hp&quot;

          *** bhennon@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):[color=blue]
          > 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 ">[/color]

          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_ran dom_img_name()? >">

          Or make your script return an actual image:

          <?
          header('Content-Type: image/gif');
          readfile('foo.g if');
          ?>

          --
          -+ Á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
          --

          Comment

          • bhennon@gmail.com

            #6
            Re: calling a php script using img src =&quot;random.p hp&quot;

            Thanks for all your help.

            I dont know php well enough to write this stuff. I am following
            instructions found here:


            will this work?


            Alvaro G. Vicario wrote:[color=blue]
            > *** bhennon@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):[color=green]
            > > 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[/color][/color]
            image[color=blue][color=green]
            > > the page is http://2006ymcanationals.com/index.php using <img
            > > src="random.php ">[/color]
            >
            > Your script does not return an image. It returns an HTML page that[/color]
            links to[color=blue]
            > an image. You cannot link to an HTML page with the <img> tag. Maybe[/color]
            you're[color=blue]
            > thinking of <iframe>?
            >
            > You could either choose a random filename:
            >
            > <img src="<?=get_ran dom_img_name()? >">
            >
            > Or make your script return an actual image:
            >
            > <?
            > header('Content-Type: image/gif');
            > readfile('foo.g if');
            > ?>
            >
            > --
            > -+ Álvaro G. Vicario - Burgos, Spain
            > +- http://www.demogracia.com (la web de humor barnizada para la[/color]
            intemperie)[color=blue]
            > ++ No envíes tu dudas a mi correo, publícalas en el grupo
            > -+ Do not send me your questions, post them to the group
            > --[/color]

            Comment

            • Brent Palmer

              #7
              Re: calling a php script using img src =&quot;random.p hp&quot;


              <bhennon@gmail. com> wrote in message
              news:1111022218 .387067.58250@l 41g2000cwc.goog legroups.com...
              Thanks for all your help.

              I dont know php well enough to write this stuff. I am following
              instructions found here:


              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.


              Comment

              • Alvaro G. Vicario

                #8
                Re: calling a php script using img src =&quot;random.p hp&quot;

                *** bhennon@gmail.c om escribió/wrote (16 Mar 2005 17:16:58 -0800):[color=blue]
                > 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?[/color]

                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
                --

                Comment

                • Dahak

                  #9
                  Re: calling a php script using img src =&quot;random.p hp&quot;

                  On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
                  made "Alvaro G. Vicario" <kAlvaroNOSPAMT HANKS@terra.es> write:
                  [color=blue]
                  >*** bhennon@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):[color=green]
                  >> 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 ">[/color]
                  >
                  >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_ran dom_img_name()? >">
                  >
                  >Or make your script return an actual image:
                  >
                  ><?
                  >header('Conten t-Type: image/gif');
                  >readfile('foo. gif');
                  >?>[/color]

                  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=ImageC reate( $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 = imagecreatefrom jpeg( $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?li nk=Tester&style =odometer"
                  height="20" align="ABSMIDDL E">
                  <<<

                  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.

                  Comment

                  • Tex John

                    #10
                    Re: calling a php script using img src =&quot;random.p hp&quot;


                    "Dahak" <Dahak_II@thefi fthimperium.com > wrote in message
                    news:pf8051td36 s9ia5eqbl1c1bsg sj81iev74@4ax.c om...[color=blue]
                    > On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
                    > made "Alvaro G. Vicario" <kAlvaroNOSPAMT HANKS@terra.es> write:
                    >[color=green]
                    > >*** bhennon@gmail.c om escribió/wrote (16 Mar 2005 13:33:26 -0800):[color=darkred]
                    > >> 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 ">[/color]
                    > >
                    > >Your script does not return an image. It returns an HTML page that links[/color][/color]
                    to[color=blue][color=green]
                    > >an image. You cannot link to an HTML page with the <img> tag. Maybe[/color][/color]
                    you're[color=blue][color=green]
                    > >thinking of <iframe>?
                    > >
                    > >You could either choose a random filename:
                    > >
                    > ><img src="<?=get_ran dom_img_name()? >">
                    > >
                    > >Or make your script return an actual image:
                    > >[/color][/color]


                    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>&nbsp;</th>
                    </tr>

                    ==== status.php has to be above Doc Root ===============

                    <?php
                    //Web Server Status v 1.2, Copyright 2002 By Ryan Schwiebert, visit

                    //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

                    //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,$po rt)= explode (':',"$link");
                    if (empty($port)) {
                    $port = 80;
                    }

                    //Test the server connection

                    $churl = @fsockopen(serv er($addr), $port, $errno, $errstr, 20);
                    #$churl = @fsockopen($add r, $port, $errno, $errstr, 20);
                    if (!$churl){
                    header("Locatio n: $dead");
                    }
                    else {
                    header("Locatio n: $live");
                    }
                    function server($addr){
                    if(strstr($addr ,"/")){$addr = substr($addr, 0, strpos($addr,
                    "/"));}
                    return $addr;
                    }
                    ?>

                    ====== end of script =====

                    hth,
                    John


                    Comment

                    • bhennon@gmail.com

                      #11
                      Re: calling a php script using img src =&quot;random.p hp&quot;


                      Tex John wrote:[color=blue]
                      > "Dahak" <Dahak_II@thefi fthimperium.com > wrote in message
                      > news:pf8051td36 s9ia5eqbl1c1bsg sj81iev74@4ax.c om...[color=green]
                      > > On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
                      > > made "Alvaro G. Vicario" <kAlvaroNOSPAMT HANKS@terra.es> write:
                      > >[color=darkred]
                      > > >*** bhennon@gmail.c om escribió/wrote (16 Mar 2005 13:33:26[/color][/color][/color]
                      -0800):[color=blue][color=green][color=darkred]
                      > > >> 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[/color][/color][/color]
                      image[color=blue][color=green][color=darkred]
                      > > >> 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[/color][/color][/color]
                      links[color=blue]
                      > to[color=green][color=darkred]
                      > > >an image. You cannot link to an HTML page with the <img> tag.[/color][/color][/color]
                      Maybe[color=blue]
                      > you're[color=green][color=darkred]
                      > > >thinking of <iframe>?
                      > > >
                      > > >You could either choose a random filename:
                      > > >
                      > > ><img src="<?=get_ran dom_img_name()? >">
                      > > >
                      > > >Or make your script return an actual image:
                      > > >[/color][/color]
                      >
                      >
                      > Here's a working example that might help. This checks to see if a[/color]
                      website is[color=blue]
                      > up and if it is, it displays a smiley gif and if not, a not so smiley[/color]
                      gif in[color=blue]
                      > a table of smileys. Now the page doesn't wait for ALL the smileys to[/color]
                      not[color=blue]
                      > time out before displaying; rather it displays the whole table[/color]
                      immediately[color=blue]
                      > and these pop up as they finish running. Now if it would only display[/color]
                      a[color=blue]
                      > "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"[/color]
                      width="37"[color=blue]
                      > height="20"></th>
                      > <th><img src="/frag/status.php?addr =mail.logon.net &port=110"[/color]
                      width="37"[color=blue]
                      > height="20"></th>
                      > <th><img src="/frag/status.php?addr =mail.logon.net " width="37"
                      > height="20"></th>
                      > <th>&nbsp;</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[/color]
                      headers are[color=blue]
                      > 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,$po rt)= explode (':',"$link");
                      > if (empty($port)) {
                      > $port = 80;
                      > }
                      >
                      > //Test the server connection
                      >
                      > $churl = @fsockopen(serv er($addr), $port, $errno, $errstr, 20);
                      > #$churl = @fsockopen($add r, $port, $errno, $errstr, 20);
                      > if (!$churl){
                      > header("Locatio n: $dead");
                      > }
                      > else {
                      > header("Locatio n: $live");
                      > }
                      > function server($addr){
                      > if(strstr($addr ,"/")){$addr = substr($addr, 0, strpos($addr,
                      > "/"));}
                      > return $addr;
                      > }
                      > ?>
                      >
                      > ====== end of script =====
                      >
                      > hth,
                      > John[/color]


                      I was never able to get this working. Some people say you cannot call a
                      php script that outputs html from within an html page and others say
                      that it works. Which is it? Looks like it works in Johns example.

                      John,
                      could you post the rest of the html from your example? Is the page
                      named index.php or index.html?

                      Is there an opening and closing php statement in the page somewhere?
                      "<?php" and "?>"

                      Thanks for your help.
                      Brad

                      Comment

                      • BKDotCom

                        #12
                        Re: calling a php script using img src =&quot;random.p hp&quot;

                        for a "processing " image use the lowsrc attribute

                        <img lowsrc="path/processing.gif" src="/frag/status.php?addr =addr.net"
                        width="37" height="20">

                        Comment

                        • BKDotCom

                          #13
                          Re: calling a php script using img src =&quot;random.p hp&quot;

                          Nobody said that..
                          what was said that the image tag needs to have a SRC attribute (not
                          href) and the SRC needs to be a url to a valid image document (whether
                          generated on the fly via a script or whatever). your image tag just
                          so happens to reference something that outputs html.. which
                          not-suprisingly gives a broken image.

                          Comment

                          Working...