473,467 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Jul 17 '05 #1
12 9665

<bh*****@gmail.com> wrote in message
news:11*********************@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.


Jul 17 '05 #2
NC
bh*****@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

Jul 17 '05 #3
bh*****@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

Jul 17 '05 #4
*** bh*****@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
--
Jul 17 '05 #5
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:
*** bh*****@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
--


Jul 17 '05 #6

<bh*****@gmail.com> wrote in message
news:11*********************@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.
Jul 17 '05 #7
*** bh*****@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
--
Jul 17 '05 #8
On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
made "Alvaro G. Vicario" <kA*****************@terra.es> write:
*** bh*****@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.
Jul 17 '05 #9

"Dahak" <Da******@thefifthimperium.com> wrote in message
news:pf********************************@4ax.com...
On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
made "Alvaro G. Vicario" <kA*****************@terra.es> write:
*** bh*****@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 toan image. You cannot link to an HTML page with the <img> tag. Maybe you'rethinking 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>&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 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
Jul 17 '05 #10

Tex John wrote:
"Dahak" <Da******@thefifthimperium.com> wrote in message
news:pf********************************@4ax.com...
On Thu, 17 Mar 2005 00:02:16 +0100, an orbiting mind-control laser
made "Alvaro G. Vicario" <kA*****************@terra.es> write:
*** bh*****@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
toan image. You cannot link to an HTML page with the <img> tag.
Maybe
you'rethinking 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>&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 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

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

Jul 17 '05 #11
for a "processing" image use the lowsrc attribute

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

Jul 17 '05 #12
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.

Jul 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Bobbitt | last post by:
I've recently decided to switch from compiled Apache/PHP to RPM's of both and I'm having a problem I can't seem to solve. I have a Perl script called php_include.cgi that parses a PHP file for...
5
by: Phil Powell | last post by:
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure...
0
by: Matt Sale | last post by:
add this to your list of how NOT to configure apache 2.x for PHP. Never add this line to the httpd.conf: AddHandler cgi-script .php sign me: perpetual student at Hard Knocks U.
3
by: David | last post by:
I found and interesting article, "Experiences of Using PHP in Large Websites" (http://www.ukuug.org/events/linux2002/papers/html/php/) , which lists some issues with scaling PHP for larger...
4
by: Jesse Noller | last post by:
Hello - I'm probably missing something here, but I have a problem where I am populating a list of lists like this: list1 = list2 = list3 = main_list =
10
by: FX | last post by:
I wanna publish a script on my site which allows me to hide image source. i have rough idea abt it. i`ll point src to some php page like: <img src="image.php"> & in tht php wat exactly shud be...
5
by: Jim Carlock | last post by:
I've set up the following using an Alias in Apache... Alias /phpdocs/ "C:/Apache/htdocs/common/docs/php/" <Directory "C:/Apache/htdocs/common/docs/php"> Options Indexes FollowSymlinks MultiViews...
3
by: Larry Leonard | last post by:
Running MSDE 2000 SP2 on Windows XP SP3. I have a T-SQL script that is relatively simple (adding constraints, inserting rows, etc.) and short (maybe 300 lines, heavily commented). It's an...
5
bilibytes
by: bilibytes | last post by:
hi, i am making a website with php OOP. i have a class called session: it has the attribues -logged_in; -user_name; -user_ip; -user_level;
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.