xWastedMindx
Technical User
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
"Hey...Where are all the chicks?" -- unknown
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 = "./img/";
// define location of image conversion programs
$img_conv_dir = "./bin/";
// define database table containing image info
$img_table = "images";
// connect with database
include ("../../includes/connect.php");
// mysql_connect("yourhost", "youruser", "password");
// mysql_select_db("dbname");
// generate unique id for use in filename
$uniq = uniqid("");
// new file name
$filename = $base_img_dir.$uniq;
// move uploaded file to destination
move_uploaded_file($HTTP_POST_FILES["file"]["tmp_name"], $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."gif2png $filename";
exec($command);
// remove original gif file and rename converted png
unlink($filename);
rename("$filename.png", $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 = "PNG";
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 = "JPG";
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 = "PNG";
break;
case 4: // bmp
// rename file to bmp
rename($filename, "$filename.bmp");
// convert bmp to png using shell command
$command = $img_conv_dir."bmptoppm $filename.bmp | ".
$img_conv_dir."pnmtopng > $filename";
exec($command);
// remove original bmp
unlink("$filename.bmp");
// 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 = "PNG";
break;
default:
break;
}
// retrieve image file size
$imgbytes = filesize($filename);
// insert image into db
mysql_query("INSERT INTO $img_table (img_file, img_type, img_height,
img_width, img_bytes, img_title, img_descr, img_alt)
VALUES('$uniq', '$img_type', ".$imginfo[1].", ".$imginfo[0].",
$imgbytes, '".addslashes($HTTP_POST_VARS["title"])."', '".
addslashes($HTTP_POST_VARS["descr"])."',
'".addslashes($HTTP_POST_VARS["alt"])."');");
// display some information
echo "Image uploaded.<br><img src=\"img.php?f($uniq)+x(300)\"><br>".
"URL: img.php?f($uniq)";
?>
"Hey...Where are all the chicks?" -- unknown