RE: [PHP] Sourcing Image file to <IMG> tag
| From: | Mark Olbert | Date: | Tue, 10 Oct 2000 20:40:01 +0000 |
| Subject: | RE: [PHP] Sourcing Image file to <IMG> tag | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-19425@lists.php.net to get a copy of this message | ||
Some additional info on this problem:
Whenever I try to access the .html file I've included in this post, the
apache error_log shows:
[Tue Oct 10 12:31:12 2000] [error] (8)Exec format error: exec of
/home/httpd/php/displayimage.php failed
[Tue Oct 10 12:31:12 2000] [error] [client 192.168.1.2] Premature end of
script headers: /home/httpd/php/displayimage.php
The .html file is:
<html>
<p>This file attempts to src a picture from a php script</p>
<img src="/php/displayimage.php">
I have aliased /php/ to /home/httpd/php in the httpd.conf file:
ScriptAlias /php/ /home/httpd/php/
#
# "@@ServerRoot@@/cgi-bin" should be changed to whatever your
ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory /home/httpd/php>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
The directories /home/httpd/php and /home/httpd/html, as well as every file
in each of them, is owned by user nobody with rwx permissions. This isn't
the way I'd normally configure the system -- the php directory should be
more secure -- but I just wanted to eliminate any potential problems.
</html>
The source code for displayimage.php is:
<script language="php">
arrgh; // This is a deliberate error; I get no message about it, so
clearly php is never
// getting to this point
$maxdim = 300; // displayimage reformats all pictures to be no more than
300 pixels wide or
// high
if( !isset($quality) )
{
$quality=30; // default quality
}
else
{
if( $quality > 100 )
{
$quality = 100;
}
if( $quality < 0 )
{
$quality = 0;
}
}
if( !isset($imagepath) ) // imagepath is the variable used to indicate the
path to the image file
// if null, a 300x300 pixel black rectangle should be created
{
// Create a dummy image saying no image selected
$newim = imagecreate($maxdim, $maxdim);
// Fill with pale yellow
$bkgnd = imagecolorallocate($newim, 255, 255, 128);
imagefill($newim, 0, 0, $bkgnd);
// Insert text
$black = imagecolorallocate($newim, 0, 0 , 0);
imagestring($newim, 10, 10, "No image selected", $black);
}
else
{
// /home/httpd/html/images is the location on my system where I store image
files
$im = imagecreatefromjpeg("/home/httpd/html/images/" . $imagepath);
$oldwidth = imagesx($im);
$oldheight = imagesy($im);
$aspect = $oldheight / $oldwidth;
if( $aspect < 1 )
{
$newwidth = $maxdim;
$newheight = $maxdim * $aspect;
}
else
{
$newheight = $maxdim;
$newwidth = $maxdim / $aspect;
}
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight,
$oldwidth, $oldheight);
}
header("Content-type: image/jpeg");
imagejpeg($newim,"",$quality);
</script>
Again, any help on how to get this script working again would be much
appreciated.
- Mark
-----Original Message-----
From: Lars Torben Wilson [mailto:torben@pinc.com]
Sent: Monday, October 09, 2000 10:32 PM
To: mark@arcabama.com
Cc: php-general@lists.php.net
Subject: RE: [PHP] Sourcing Image file to <IMG> tag
Mark Olbert writes:
> Additional info:
>
> When I examine the properties of the busted image (i.e., the <img> tag
that
> should be displaying somethting), it shows as:
>
> http://my.domain.com/displayimage.php etc
>
> This sure looks wrong, as I put all of my php scripts outside of the html
> document tree.
>
> Does this problem ring a bell with anyone?
>
> - Mark
Well, displayimage.php is gonna have to be in the document tree;
otherwise, the httpd won't be able to get at it from the img tag.
However, you probably don't need the http://my.domain.com at
the
beginning, as long as the displayimage.php script is properly located.
Perhaps you edited the HTML source with something which rewrote the
tags for you? I've seen some 'clever' software which thinks that this
is a cool thing to do.
Another possibility: *always* quote your tag attributes, even if they
don't need it. Some editors don't do this, and even though it's not
strictly necessary in all cases, it's a habit which removes one more
potential problem.
Have you installed a new server but changed the compilation options?
Can we see the actual tag & the shortest possible script which
reproduce the problem?
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+