ImageCreateFromJPEG fails if path contains apostrophe ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tim.landgraf@googlemail.com

    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 @ImageCreateFro mJPEG fails.
    anyone knows this problem and possible workarounds?

    thank you,
    tim

    here is the code
    [list.php]
    ....
    while ( $file = readdir($dirhan dle) )
    {
    echo "
    ....
    <a href="show_imag e.php?path='.ra wurlencode($dir .'/'.$file).'">sho w</
    a><br />
    ....
    ";
    }
    ....

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

    with function LoadJpeg defined as:

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

  • Sjoerd

    #2
    Re: ImageCreateFrom JPEG fails if path contains apostrophe ?

    tim.landgraf@go oglemail.com wrote:
    if there is a file
    with an apostrophe in it the GD function @ImageCreateFro mJPEG 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:



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

    Comment

    Working...