Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 27th, 2007, 08:15 PM
tim.landgraf@googlemail.com
Guest
 
Posts: n/a
Default ImageCreateFromJPEG fails if path contains apostrophe ?

hi there,

i am experiencing a strange problem. i am iterating through a given
directory, selecting only jpg - images that are then resized and
inserted into a database. everything works, but if there is a file
with an apostrophe in it the GD function @ImageCreateFromJPEG fails.
anyone knows this problem and possible workarounds?

thank you,
tim

here is the code
[list.php]
....
while ( $file = readdir($dirhandle) )
{
echo "
....
<a href="show_image.php?path='.rawurlencode($dir.'/'.$file).'">show</
a><br />
....
";
}
....

[show_image.php]
....
if ( $image = LoadJpeg(rawurldecode($_GET["path"])))
{
header("content-type:image/jpeg");
imagejpeg($image);
}
....

with function LoadJpeg defined as:

//taken from http://www.hpserver.de/php/function....efromjpeg.html
function LoadJpeg ($imgname) {
$im = @ImageCreateFromJPEG ($imgname); /* Versuch, Datei zu öffnen
*/
if (!$im) { /* Prüfen, ob fehlgeschlagen
*/
$im = ImageCreate (150, 30); /* Erzeugen eines leeren
Bildes */
$bgc = ImageColorAllocate ($im, 255, 255, 255);
$tc = ImageColorAllocate ($im, 0, 0, 0);
ImageFilledRectangle ($im, 0, 0, 150, 30, $bgc);
/* Ausgabe einer Fehlermeldung */
ImageString($im, 1, 5, 5, "Fehler beim Öffnen von: $imgname",
$tc);
}
return $im;
}

  #2  
Old February 27th, 2007, 11:05 PM
Sjoerd
Guest
 
Posts: n/a
Default Re: ImageCreateFromJPEG fails if path contains apostrophe ?

tim.landgraf@googlemail.com wrote:
Quote:
if there is a file
with an apostrophe in it the GD function @ImageCreateFromJPEG fails.
anyone knows this problem and possible workarounds?
Since you are passing the path of the file using GET variables, you may
be a victim of "magic quotes". See:
http://www.php.net/manual/en/ref.inf...gic-quotes-gpc
http://www.php.net/manual/en/function.stripslashes.php

To be sure, echo the filename and see if it is correct.
 

Bookmarks

Thread Tools

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

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles