469,312 Members | 2,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Image return /print

me
Hey all,
well i am also a newbie :)

i saw this on many sites:
<img src="somephp.php?blabla" width="100">

how can i make that to?

i want to reffer to a php file that returns or prints a jpg image and in the
<img src=must be a php url>

Best regards M
Jul 17 '05 #1
7 14890
me wrote:
Hey all,
well i am also a newbie :)

i saw this on many sites:
<img src="somephp.php?blabla" width="100">

how can i make that to?

i want to reffer to a php file that returns or prints a jpg image and in
the <img src=must be a php url>

Best regards M


Hi,

You should somephp.php?blabla return an image, including the right headers
for MIME-TYPE and such.
Should work as you described above.

The trouble will be generating a script that does that. You will have to do
some more research on imagelibs in PHP.

Good luck,
Erwin Moller
Jul 17 '05 #2
me

"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:3f***********************@news.xs4all.nl...
me wrote:
Hey all,
well i am also a newbie :)

i saw this on many sites:
<img src="somephp.php?blabla" width="100">

how can i make that to?

i want to reffer to a php file that returns or prints a jpg image and in
the <img src=must be a php url>

Best regards M
Hi,

You should somephp.php?blabla return an image, including the right headers
for MIME-TYPE and such.
Should work as you described above.

The trouble will be generating a script that does that. You will have to

do some more research on imagelibs in PHP.

Good luck,
Erwin Moller


Thanks,

i did some testing with this code:

header("Contet-type: image/jpeg");
$theURL="image.jpg";
if(!($fp=fopen($theURL,"rb")))
{
print("Could not open the URL.");
exit;
}
$contents=fread($fp,1000000);
print($contents);
fclose($fp);
But must i always set the header("Contet-type: image/jpeg") before the code
begins or can i make first a musql query orso to get the rigth image and
then print the header("Contet-type: image/jpeg");?
Jul 17 '05 #3
me wrote:

"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:3f***********************@news.xs4all.nl...
me wrote:
> Hey all,
> well i am also a newbie :)
>
> i saw this on many sites:
> <img src="somephp.php?blabla" width="100">
>
> how can i make that to?
>
> i want to reffer to a php file that returns or prints a jpg image and
> in the <img src=must be a php url>
>
> Best regards M
Hi,

You should somephp.php?blabla return an image, including the right
headers for MIME-TYPE and such.
Should work as you described above.

The trouble will be generating a script that does that. You will have to

do
some more research on imagelibs in PHP.

Good luck,
Erwin Moller


Thanks,

i did some testing with this code:

header("Contet-type: image/jpeg");


that is content-type, no contet-type.
$theURL="image.jpg";
if(!($fp=fopen($theURL,"rb")))
{
print("Could not open the URL.");
this is a bit odd. You have set the header to image, but your output is
plain text..
Not good.

Your html-page is asking for an image, and your script should return one.
In your case, where it cannot find the right image, try to send back an
image you know that exists containing "NOT AVAILABLE" written on it or
somethinf like that.
Do not send plain text to the browser when it expects an image.
Better write an error to some logfile.
exit;
}
$contents=fread($fp,1000000);
print($contents);
fclose($fp);
But must i always set the header("Contet-type: image/jpeg") before the
code begins or can i make first a musql query orso to get the rigth image
and then print the header("Contet-type: image/jpeg");?


You can do whatever you like AS LONG AS YOU DO NOT GENERATE OUTPUT.
:-)
The headers should come first.

Jul 17 '05 #4

On 29-Sep-2003, "me" <so*****@microsoft.com> wrote:
i saw this on many sites:
<img src="somephp.php?blabla" width="100">

how can i make that to?


<img src="getimage.php?fn=image1" ...>

getimage.php:
<?php

if (isset($_GET['fn']))
$image = $_GET['fn'];
else
$image = 'error';

header("Content-Type: image/jpeg\n");
header("Content-Transfer-Encoding: binary");

$fp=fopen("images/$image.jpg" , "r");
if ($fp)
fpassthru($fp);

?>
--
Tom Thackrey
www.creative-light.com
Jul 17 '05 #5

"me" <so*****@microsoft.com> wrote in message
news:Yv***********************@pollux.casema.net.. .

"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:3f***********************@news.xs4all.nl...
me wrote:
Hey all,
well i am also a newbie :)

i saw this on many sites:
<img src="somephp.php?blabla" width="100">

how can i make that to?

i want to reffer to a php file that returns or prints a jpg image and in the <img src=must be a php url>

Best regards M
Hi,

You should somephp.php?blabla return an image, including the right headers for MIME-TYPE and such.
Should work as you described above.

The trouble will be generating a script that does that. You will have to

do
some more research on imagelibs in PHP.

Good luck,
Erwin Moller


Thanks,

i did some testing with this code:

header("Contet-type: image/jpeg");
$theURL="image.jpg";
if(!($fp=fopen($theURL,"rb")))
{
print("Could not open the URL.");
exit;
}
$contents=fread($fp,1000000);
print($contents);
fclose($fp);
But must i always set the header("Contet-type: image/jpeg") before the

code begins or can i make first a musql query orso to get the rigth image and
then print the header("Contet-type: image/jpeg");?


Maybe try "Content-type" and not "Contet-type" :)
Jul 17 '05 #6
On Mon, 29 Sep 2003 15:54:32 GMT, "Tom Thackrey"
<to***@creative-light.com> wrote:
<img src="getimage.php?fn=image1" ...>

getimage.php:
<?php

if (isset($_GET['fn']))
$image = $_GET['fn'];
else
$image = 'error';

header("Content-Type: image/jpeg\n");
header("Content-Transfer-Encoding: binary");

$fp=fopen("images/$image.jpg" , "r");
if ($fp)
fpassthru($fp);

?>


another way to do it:

getimage.php:
<?php
if (isset($_GET['fn']))
{
$image = $_GET['fn'];
header("Location: images/$image.jpg");
}
else
{
header("HTTP/1.0 404 Not Found");
}
?>

- allan savolainen

Jul 17 '05 #7
Jason wrote:

"me" <so*****@microsoft.com> wrote in message
news:Yv***********************@pollux.casema.net.. .

"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:3f***********************@news.xs4all.nl...
> me wrote:
>
> > Hey all,
> > well i am also a newbie :)
> >
> > i saw this on many sites:
> > <img src="somephp.php?blabla" width="100">
> >
> > how can i make that to?
> >
> > i want to reffer to a php file that returns or prints a jpg image and in > > the <img src=must be a php url>
> >
> > Best regards M
>
> Hi,
>
> You should somephp.php?blabla return an image, including the right headers > for MIME-TYPE and such.
> Should work as you described above.
>
> The trouble will be generating a script that does that. You will have
> to

do
> some more research on imagelibs in PHP.
>
> Good luck,
> Erwin Moller


Thanks,

i did some testing with this code:

header("Contet-type: image/jpeg");
$theURL="image.jpg";
if(!($fp=fopen($theURL,"rb")))
{
print("Could not open the URL.");
exit;
}
$contents=fread($fp,1000000);
print($contents);
fclose($fp);
But must i always set the header("Contet-type: image/jpeg") before the

code
begins or can i make first a musql query orso to get the rigth image and
then print the header("Contet-type: image/jpeg");?


Maybe try "Content-type" and not "Contet-type" :)


Hi Jason,

That might help maybe. ;-)

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Henri Schomäcker | last post: by
9 posts views Thread by Steffen Brodowski | last post: by
9 posts views Thread by matthiasjanes | last post: by
17 posts views Thread by PyPK | last post: by
5 posts views Thread by Tompa | last post: by
reply views Thread by Sergei Shelukhin | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.