Here is my code for uploading the files. I have tried commenting out the create thumbnail part and the smaller image part in turn and I still get the same error.
The next code is the upload code for a thumbnail depicting an album and this works alright. Any help would be apreciated.
<?php
$uploadid = $_SESSION['loginID'];
$uploaddate = date("j-n-y, G:i:s");
$uploadedfile=$_FILES['userfile']['tmp_name'];
$ph_category=$_POST['category'];
$ph_caption=$_POST['caption'];
if ($ph_category == "Select Category") {
echo ("You have not selected a category for this photograph<BR>\n");
exit;
}
//check to see if a file is uploaded at all
if ($userfile_size >= 2000000) {
echo ("This file is too large<BR>\n");
echo ("Please reduce the resolution or size of photograph<BR>\n");
echo ("The file size must be below 2 megabytes and try again<BR>\n");
exit;
}
//check for empty file
echo ("filesize: $userfile_size<BR>\n");
if ($userfile_size==0)
{
echo "Error: File uploaded has no image";
exit;
}
// create new name for file
$randomnumber = rand();
$date = date("Gis");
$newname = $date . $randomnumber;
//echo ("name: $newname<BR>\n");
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
if ($width > $height) {
$newwidth=500;
$newheight=($height/$width)*500;
}
if ($width < $height) {
$newheight=375;
$newwidth=($width/$height)*375;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename= "../gallery/".$newname. ".jpg";
imagejpeg($tmp,$filename,100);
if ($width > $height) {
$thwidth=100;
$thheight=($height/$width)*100;
}
if ($width < $height) {
$thheight=75;
$thwidth=($width/$height)*75;
}
$tmp_th=imagecreatetruecolor($thwidth,$thheight);
imagecopyresampled($tmp_th,$src,0,0,0,0,$thwidth,$thheight,$width,$height);
$thumbname= "../gallery/thumbs/".$newname. ".jpg";
imagejpeg($tmp_th,$thumbname,100);
echo ("filename: $filename<BR>\n");
echo ("thumbnail: $thumbname<BR>\n");
$query = "INSERT INTO gallery_photos (photo_filename, photo_thumbnail, photo_caption, photo_category, upload_id, upload_date )". "VALUES ('$filename','$thumbname','$ph_caption', '$ph_category','$uploadid','$uploaddate')";
//echo ("The query is: <BR>$query<P>\n");
if (mysql_db_query ($dbname, $query, $link)){
echo ("Your Photograph was successfully uploaded!<BR>\n");
} else {
echo(mysql_error());
echo ("Your photograph could not be uploaded.<BR>\n");
}
mysql_close ($link);
?>
code for uploading the album image (this works)
<?php
$uploadid = $_SESSION['loginID'];
$uploaddate = date("j-n-y, G:i:s");
$uploadedfile=$_FILES['cat_file']['tmp_name'];
$category=$_POST['cat_name'];
//check to see if a file is uploaded at all
if ($cat_file_size >= 2000000) {
echo ("This file is too large<BR>\n");
echo ("Please reduce the resolution or size of photograph<BR>\n");
echo ("The file size must be below 2 megabytes and try again<BR>\n");
exit;
}
$albumname="../gallery/albums/$cat_file_name";
//check for empty file
echo ("filesize: $cat_file_size<BR>\n");
if ($cat_file_size==0)
{
echo "Error: File uploaded has no image";
exit;
}
// create new name for file
$randomnumber = rand();
$date = date("Gis");
$newname = $date . $randomnumber;
echo ("name: $newname<BR>\n");
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
if ($width > $height) {
$newwidth=80;
$newheight=($height/$width)*80;
}
if ($width < $height) {
$newheight=60;
$newwidth=($width/$height)*60;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename= "../gallery/albums/".$newname. ".jpg";
imagejpeg($tmp,$filename,100);
$query = "INSERT INTO gallery_category (category, cat_image, description, upload_id, upload_date )". "VALUES ('$category','$filename', '$description', '$uploadid', '$uploaddate')";
//echo ("The query is: <BR>$query<P>\n");
if (mysql_db_query ($dbname, $query, $link)){
echo ("Your Album was successfully created!<BR>\n");
} else {
echo(mysql_error());
echo ("Your Album could not be created.<BR>\n");
}
mysql_close ($link);
?>