Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

imagecreatefromjpeg not working?

Status
Not open for further replies.

xWastedMindx

Technical User
Sep 3, 2002
67
0
0
US
I got a problem.

I have a script I'm working with ... following a tutorial found on DevArticles.com.
The tutorial can be found here:

Anyway, it seems that the upload script works fine.. except for the JPG checking. I can comment out that section, and it passes the GIF, BMP, and PNG sections. But otherwise gets stuck on JPG. Also.. I just noticed that even though the errors are displayed the file seems to get uploaded anyway

Fatal error: Call to undefined function: imagecreatefromjpeg() in /var/ on line 77

Any ideas?


PHP 4.3.1, Apache 2, and MySQL 4.0.11 - Mandrake 9.1


Code:
<?php
// define the base image dir
$base_img_dir = &quot;./img/&quot;;

// define location of image conversion programs
$img_conv_dir = &quot;./bin/&quot;;

// define database table containing image info
$img_table = &quot;images&quot;;

// connect with database
include (&quot;../../includes/connect.php&quot;);
// mysql_connect(&quot;yourhost&quot;, &quot;youruser&quot;, &quot;password&quot;);
// mysql_select_db(&quot;dbname&quot;);

// generate unique id for use in filename
$uniq = uniqid(&quot;&quot;);

// new file name
$filename = $base_img_dir.$uniq;

// move uploaded file to destination
move_uploaded_file($HTTP_POST_FILES[&quot;file&quot;][&quot;tmp_name&quot;], $filename);

// retrieve image info
$imginfo = getimagesize($filename);

// handle image according to type
switch ($imginfo[2]) {
    case 1: // gif
        // convert gif to png using shell command
        $command = $img_conv_dir.&quot;gif2png $filename&quot;;
        exec($command);

        // remove original gif file and rename converted png
        unlink($filename);
        rename(&quot;$filename.png&quot;, $filename);

        // check png image by loading and saving the file
        //  to prevent wrong uploaded files and errors
        $img = imagecreatefrompng($filename);
        imagepng($img, $filename);
        imagedestroy($img);

        // set image type to png
        $img_type = &quot;PNG&quot;;
        break;

    case 2: // jpeg
        // check jpeg image by loading and saving the file
        //  to prevent wrong uploaded files and errors
      	  $img = imagecreatefromjpeg($filename);
      	  imagejpeg($img, $filename);
      	  imagedestroy($img);
        
        // set image type to jpeg
        $img_type = &quot;JPG&quot;;
        break;

    case 3: // png
        // check png image by loading and saving the file
        //  to prevent wrong uploaded files and errors
        $img = imagecreatefrompng($filename);
        imagepng($img, $filename);
        imagedestroy($img);
        
        // set image type to png
        $img_type = &quot;PNG&quot;;
        break;

    case 4: // bmp
        // rename file to bmp
        rename($filename, &quot;$filename.bmp&quot;);
        
        // convert bmp to png using shell command
        $command = $img_conv_dir.&quot;bmptoppm $filename.bmp | &quot;.
                   $img_conv_dir.&quot;pnmtopng > $filename&quot;;
        exec($command);

        // remove original bmp
        unlink(&quot;$filename.bmp&quot;);
        
        // check png image by loading and saving the file
        //  to prevent wrong uploaded files and errors
        $img = imagecreatefrompng($filename);
        imagepng($img, $filename);
        imagedestroy($img);
        
        // set image type to png
        $img_type = &quot;PNG&quot;;
        break;

    default:
        break;
}

// retrieve image file size
$imgbytes = filesize($filename);

// insert image into db
mysql_query(&quot;INSERT INTO $img_table (img_file, img_type, img_height,
   img_width, img_bytes, img_title, img_descr, img_alt)
  VALUES('$uniq', '$img_type', &quot;.$imginfo[1].&quot;, &quot;.$imginfo[0].&quot;,
         $imgbytes, '&quot;.addslashes($HTTP_POST_VARS[&quot;title&quot;]).&quot;', '&quot;.
         addslashes($HTTP_POST_VARS[&quot;descr&quot;]).&quot;',
         '&quot;.addslashes($HTTP_POST_VARS[&quot;alt&quot;]).&quot;');&quot;);

// display some information
echo &quot;Image uploaded.<br><img src=\&quot;img.php?f($uniq)+x(300)\&quot;><br>&quot;.
     &quot;URL: img.php?f($uniq)&quot;;
?>

&quot;Hey...Where are all the chicks?&quot; -- unknown
 
It appears I don't. I don't have a GD section in my phpinfo().

Definately strange.. because I downloaded it from ADVX.org..and you think they'd at least have JPG/GD support. But it seems they don't have any newer updates for PHP yet...

If I were to recompile to the new version and add support using the commands supplied in the phpinfo() .. and add in jpeg and GD support, it should be installed into the same locations, correct?
That way I won't have the RPM install and my source install in two different locations.. and it wont screw anything up. Right?

Also.. how would I go about adding those commands into the config below?

Configure-Commands from phpinfo() :

'./configure' '--prefix=/usr' '--libdir=/usr/lib' '--enable-discard-path' '--disable-force-cgi-redirect' '--enable-shared' '--disable-static' '--disable-debug' '--disable-rpath' '--enable-pic' '--enable-inline-optimization' '--enable-memory-limit' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php' '--with-pear=/usr/share/pear' '--enable-magic-quotes' '--enable-debugger' '--enable-track-vars' '--with-exec-dir=/usr/bin' '--with-versioning' '--with-mod_charset' '--with-regex=php' '--enable-track-vars' '--enable-trans-sid' '--enable-safe-mode' '--enable-ctype' '--enable-ftp' '--with-gettext=/usr' '--enable-posix' '--enable-session' '--enable-sysvsem' '--enable-sysvshm' '--enable-yp' '--with-openssl=/usr' '--without-kerberos' '--with-ttf' '--with-freetype-dir=/usr' '--with-zlib=/usr' '--with-zlib=/usr' '--with-zlib-dir=/usr'

&quot;Hey...Where are all the chicks?&quot; -- unknown
 
Seems I figured out an easier way to install it.
At least the GD part anyway.
in the Konsole.. just typed urpmi php-gd
It asked for CD-2 and installed it for me.
Now it shows up in the phpinfo() and I have JPG support :)

Thanks for the help!

&quot;Hey...Where are all the chicks?&quot; -- unknown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top