Usenet Forums

Usenet Forums (http://www.usenet-forums.com/)
-   PHP Language (http://www.usenet-forums.com/php-language/)
-   -   Image return /print (http://www.usenet-forums.com/php-language/13812-image-return-print.html)

me 09-29-2003 10:15 AM

Image return /print
 
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



Erwin Moller 09-29-2003 11:56 AM

Re: Image return /print
 
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

me 09-29-2003 12:16 PM

Re: Image return /print
 

"Erwin Moller"
<since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in
message news:3f780f80$0$58709$e4fe514c@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");?



Erwin Moller 09-29-2003 02:17 PM

Re: Image return /print
 
me wrote:

>
> "Erwin Moller"
> <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in
> message news:3f780f80$0$58709$e4fe514c@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.


Tom Thackrey 09-29-2003 04:54 PM

Re: Image return /print
 

On 29-Sep-2003, "me" <someone@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

Jason 09-29-2003 07:51 PM

Re: Image return /print
 

"me" <someone@microsoft.com> wrote in message
news:YvUdb.391862$0W5.11564308@pollux.casema.net.. .
>
> "Erwin Moller"
> <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in
> message news:3f780f80$0$58709$e4fe514c@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" :)



Allan Savolainen 09-30-2003 11:44 AM

Re: Image return /print
 
On Mon, 29 Sep 2003 15:54:32 GMT, "Tom Thackrey"
<tomnr@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


Erwin Moller 10-03-2003 10:18 AM

Re: Image return /print
 
Jason wrote:

>
> "me" <someone@microsoft.com> wrote in message
> news:YvUdb.391862$0W5.11564308@pollux.casema.net.. .
>>
>> "Erwin Moller"
>> <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in
>> message news:3f780f80$0$58709$e4fe514c@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. ;-)



All times are GMT +1. The time now is 05:37 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0