passing a url to a page

This is a discussion on passing a url to a page within the PHP General forums, part of the PHP Programming Forums category; I have a display_image.php page <?php $image = imagecreatefromjpeg($img_url); if ($image === false) { exit; } // Get original width and height ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-15-2007
Ross
 
Posts: n/a
Default passing a url to a page

I have a display_image.php page

<?php



$image = imagecreatefromjpeg($img_url);
if ($image === false) { exit; }

// Get original width and height
echo $width = imagesx($image);
echo $height = imagesy($image);

// New width and height
$new_width = 200;
$new_height = 150;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);

// Display resized image
;
header('Content-type: image/jpeg');
imagejpeg($image_resized);
exit();

?>


I want to output this as an image but cannot get it working. I need to pass
the image url something like this I thought would work

echo "<img src=\"display_image.php?img_url=$image_url>";


any ideas?
Reply With Quote
  #2 (permalink)  
Old 06-15-2007
Zoltán Németh
 
Posts: n/a
Default Re: [PHP] passing a url to a page

2007. 06. 15, péntek keltezéssel 14.45-kor Ross ezt Ã*rta:
> I have a display_image.php page
>
> <?php
>
>
>
> $image = imagecreatefromjpeg($img_url);


where do you get $img_url from? GET request?
then do something like

$img_url = $_GET['img_url'];
if (!file_exists($img_url)) die "bad hacker";

before the above line. this will let you get rid of register_globals,
and does a basic check of input, which is always very important

> if ($image === false) { exit; }
>
> // Get original width and height
> echo $width = imagesx($image);
> echo $height = imagesy($image);
>
> // New width and height
> $new_width = 200;
> $new_height = 150;
>
> // Resample
> $image_resized = imagecreatetruecolor($new_width, $new_height);
> imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width,
> $new_height, $width, $height);
>
> // Display resized image
> ;
> header('Content-type: image/jpeg');
> imagejpeg($image_resized);
> exit();
>
> ?>
>
>
> I want to output this as an image but cannot get it working. I need to pass
> the image url something like this I thought would work
>
> echo "<img src=\"display_image.php?img_url=$image_url>";


this should work. what do you mean by not working? do you get any error
message? anything? without information no one can tell you what's
wrong...

greets
Zoltán Németh

>
>
> any ideas?
>

Reply With Quote
  #3 (permalink)  
Old 06-15-2007
ross@aztechost.com
 
Posts: n/a
Default Re: [PHP] passing a url to a page

Nothing happens no errors or anything I tried to debug using
include('display_image.php?img_url=$image_url') I got a parse error.

I would rather use buffers if this is possible?
----- Original Message -----
From: "Zoltán Németh" <znemeth@alterationx.hu>
To: "Ross" <ross@aztechost.com>
Cc: <php-general@lists.php.net>
Sent: Friday, June 15, 2007 3:03 PM
Subject: Re: [php] passing a url to a page


2007. 06. 15, péntek keltezéssel 14.45-kor Ross ezt Ã*rta:
> I have a display_image.php page
>
> <?php
>
>
>
> $image = imagecreatefromjpeg($img_url);


where do you get $img_url from? GET request?
then do something like

$img_url = $_GET['img_url'];
if (!file_exists($img_url)) die "bad hacker";

before the above line. this will let you get rid of register_globals,
and does a basic check of input, which is always very important

> if ($image === false) { exit; }
>
> // Get original width and height
> echo $width = imagesx($image);
> echo $height = imagesy($image);
>
> // New width and height
> $new_width = 200;
> $new_height = 150;
>
> // Resample
> $image_resized = imagecreatetruecolor($new_width, $new_height);
> imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width,
> $new_height, $width, $height);
>
> // Display resized image
> ;
> header('Content-type: image/jpeg');
> imagejpeg($image_resized);
> exit();
>
> ?>
>
>
> I want to output this as an image but cannot get it working. I need to
> pass
> the image url something like this I thought would work
>
> echo "<img src=\"display_image.php?img_url=$image_url>";


this should work. what do you mean by not working? do you get any error
message? anything? without information no one can tell you what's
wrong...

greets
Zoltán Németh

>
>
> any ideas?
>

Reply With Quote
  #4 (permalink)  
Old 06-15-2007
Stut
 
Posts: n/a
Default Re: [PHP] passing a url to a page

ross@aztechost.com wrote:
> Nothing happens no errors or anything I tried to debug using
> include('display_image.php?img_url=$image_url') I got a parse error.
>
> I would rather use buffers if this is possible?


You can't parse GET parameters with include. Try this...

$_GET['img_url'] = $image_url;
include 'display_image.php';

Or better yet, make a simple HTML file with just an image tag.

-Stut
Reply With Quote
  #5 (permalink)  
Old 06-15-2007
Daniel Brown
 
Posts: n/a
Default Re: [PHP] passing a url to a page

On 6/15/07, ross@aztechost.com <ross@aztechost.com> wrote:
> Nothing happens no errors or anything I tried to debug using
> include('display_image.php?img_url=$image_url') I got a parse error.


You can't include a file with a query string attached. However,
you /can/ do:

<?
$image_url = 'http://www.pr0nsite.com/gallery/big-boobs.jpg'; //
Your favorite!
include('display_image.php');
?>

However, it won't work if display_image.php expects $image_url to
specifically be passed as a $_GET[] variable --- which, on a
production site, it sure should, rather than accepting globals.

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107
Reply With Quote
  #6 (permalink)  
Old 06-15-2007
Zoltán Németh
 
Posts: n/a
Default Re: [PHP] passing a url to a page

2007. 06. 15, péntek keltezéssel 15.28-kor ross@aztechost.com ezt Ã*rta:
> Nothing happens no errors or anything I tried to debug using
> include('display_image.php?img_url=$image_url') I got a parse error.


of course. include is totally different stuff, you can not give GET
parameters when including

what happens if you try to view display.image.php?img_url=something in
your browser? try it with a valid img_url value and an invalid one and
see if it throws any errors or anything

greets
Zoltán Németh

>
> I would rather use buffers if this is possible?
> ----- Original Message -----
> From: "Zoltán Németh" <znemeth@alterationx.hu>
> To: "Ross" <ross@aztechost.com>
> Cc: <php-general@lists.php.net>
> Sent: Friday, June 15, 2007 3:03 PM
> Subject: Re: [php] passing a url to a page
>
>
> 2007. 06. 15, péntek keltezéssel 14.45-kor Ross ezt Ã*rta:
> > I have a display_image.php page
> >
> > <?php
> >
> >
> >
> > $image = imagecreatefromjpeg($img_url);

>
> where do you get $img_url from? GET request?
> then do something like
>
> $img_url = $_GET['img_url'];
> if (!file_exists($img_url)) die "bad hacker";
>
> before the above line. this will let you get rid of register_globals,
> and does a basic check of input, which is always very important
>
> > if ($image === false) { exit; }
> >
> > // Get original width and height
> > echo $width = imagesx($image);
> > echo $height = imagesy($image);
> >
> > // New width and height
> > $new_width = 200;
> > $new_height = 150;
> >
> > // Resample
> > $image_resized = imagecreatetruecolor($new_width, $new_height);
> > imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width,
> > $new_height, $width, $height);
> >
> > // Display resized image
> > ;
> > header('Content-type: image/jpeg');
> > imagejpeg($image_resized);
> > exit();
> >
> > ?>
> >
> >
> > I want to output this as an image but cannot get it working. I need to
> > pass
> > the image url something like this I thought would work
> >
> > echo "<img src=\"display_image.php?img_url=$image_url>";

>
> this should work. what do you mean by not working? do you get any error
> message? anything? without information no one can tell you what's
> wrong...
>
> greets
> Zoltán Németh
>
> >
> >
> > any ideas?
> >

>
>
>

Reply With Quote
  #7 (permalink)  
Old 06-15-2007
Stut
 
Posts: n/a
Default Re: [PHP] passing a url to a page

Daniel Brown wrote:
> $image_url = 'http://www.pr0nsite.com/gallery/big-boobs.jpg';


Well that was just too disappointing for a Friday afternoon. Ya tease!

-Stut
Reply With Quote
  #8 (permalink)  
Old 06-15-2007
Jochem Maas
 
Posts: n/a
Default Re: [PHP] passing a url to a page

Zoltán Németh wrote:
> 2007. 06. 15, péntek keltezéssel 14.45-kor Ross ezt Ã*rta:
>> I have a display_image.php page
>>
>> <?php
>>
>>
>>
>> $image = imagecreatefromjpeg($img_url);

>
> where do you get $img_url from? GET request?
> then do something like
>
> $img_url = $_GET['img_url'];
> if (!file_exists($img_url)) die "bad hacker";


I have /etc/passwd on my system - I'd rather not have
the potential for some hacker to abuse a bug in GDlib that allows
extraction/output of abitrary files ...

SO ... although Zoltan (I can't f-ing remember which is your first name,
because first came last, and then it might have been switched for the
benefit of american who can't grasp that some people somewhere actually do
things differently, but then again it might not have been - oh and you
can forget the diacritics - I'm just to lazy ;-)) is right in that you
should check the requested $img_url I would add that the checks/constraints
should be much more rigid, e.g.:

$file = '/path/to/my/image/store/'.basename($_GET['img_url']);
if (file_exists($file)) die "ya momma.";
Reply With Quote
  #9 (permalink)  
Old 06-15-2007
ross@aztechost.com
 
Posts: n/a
Default Re: [PHP] passing a url to a page

I have manually put in the url my display_image.php page to debug as
sugested and all I get is the URL of the display_image.php page output on
the screen.

This is what I see
http://xxxxxxxxxxxxxxx.co.uk/common/display_image.php


this is the display_image.php file:

$img_url="http://www.xxxxxxxxxxxxx.co.uk/images/ENapt63377/4.jpg";

$image = imagecreatefromjpeg($img_url);
if ($image === false) { exit; }

// Get original width and height
echo $width = imagesx($image);
echo $height = imagesy($image);

// New width and height
$new_width = 200;
$new_height = 150;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width,
$new_height, $width, $height);

// Display resized image

header('Content-type: image/jpeg');
imagejpeg($image_resized);
exit();
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



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


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