Hi everyone, I need some help, go figure. I have a php photo upload tool that someone built for me a while back but it doesn’t seem to work and nothing I do seams to fix it.
Everytime I try to load the image it gives me the following error:
“Error! Problem [6] reading full size image”
I have included the php file below I use to load the image. I don’t know if I maybe have something setup on the server wrong or what. It used to work on our old server, but never tried it till now on our new server.
PHP file Below:
THANKS
<? /* -*-hm--html-*-
*---
*
* File: LoadPic.php
* CVS: $Revision: 1.3 $
* Description: Load a picture into the database
* Author:
* Created: Fri Apr 25 21:11:58 2003
* Modified: Sat Oct 18 12:33:57 2003
* Modified by:
* Language: PHP
* Package: N/A
* Status:
*
*
*
* Load a photo (and optionally create a category) into the
* photo database.
*
* LoadPhoto.php will ask the user for a photo and information
* about a photo, and then load the photo into the photo directory
* Creating a thumbnail in the "Thumbs" subdirectory, and storing
* the photo information in the 'Images' table, creating a category
* if needed.
*
* Uses "Connect.php" to determine database (and other) info.
* Uses "PhotoUtil.php" for utility functions
*
* Photo information is stored in the "Images" table
* Category information is stored in the "Categories" table
*---
*/
if (!$Back) $Back = getenv("HTTP_REFERER");
require_once("Connect.php");
require_once("PhotoUtil.php");
$numCat = 0;
$categories = array();
$categories["none"] = 0;
$categories["Add New"] = -1;
$numCat = BuildCategories($categories);
?>
<html>
<?
if ($submitted) {
/* Uncomment for debugging
echo "PhotoDir = $photoDir<br>n";
echo "Back = $Back<br>n";
echo "Caption = $caption<br>n";
echo "Desc = $Desc<br>n";
echo "Category = $category<br>n";
echo "Category Name = $categoryName<br>n";
echo "localName = $localName<br>n";
echo "dlName = $dlName<br>n";
*/
?>
<head>
<title>Image Added</title>
<!-- Changed by: Lew Gaiter III, 24-Oct-2003 -->
</head>
<body>
<h1>Image Added</h1>
<?
if ($category == -1) {
$query = "INSERT INTO `Categories` (`catName` )n";
$query .= "VALUES ('$categoryName')";
$res = mysql_query($query);
if ($res) {
$category = mysql_insert_id();
echo "Added category '$categoryName'<br>n";
} else {
echo "Category Storage error: " . mysql_error() . "<br>n";
}
}
/*
* Read the image
*/
$dir_uri = apache_lookup_uri($photoDir);
$dir = $dir_uri->filename;
if (@filetype($dir) != "dir") {
if (@filetype($dir)) {
die("Error! $photoDir exists and is <b>not</b> a directory");
}
if (!mkdir($dir, 0775)) {
die("Error creating $dir");
}
}
$dir_uri = apache_lookup_uri("$photoDir/Thumbs");
$dir = $dir_uri->filename;
if (@filetype("$dir") != "dir") {
if (@filetype("$dir")) {
die("Error! $photoDir/Thumbs exists " .
"and is <b>not</b> a directory");
}
if (!mkdir("$dir", 0775)) {
die("Error creating $dir");
}
}
$err = 0;
$img = "$photoDir/$localName.jpg";
$img_uri = apache_lookup_uri($img);
$img_fn = $img_uri->filename;
$image = LoadPhotoJpg("theFile", $img_fn, 1024, 768);
if ($image) {
echo "Error! Problem [$image] reading full size image<br>n";
$err = 1;
}
$tn = "$photoDir/Thumbs/$localName.jpg";
$tn_uri = apache_lookup_uri($tn);
$tn_fn = $tn_uri->filename;
if (!$err) {
$thumb = LoadPhotoJpg("theFile", $tn_fn, 100, 100);
if ($thumb) {
echo "Error! Problem [$thumb] reading thumbnail<br>n";
$err = 1;
}
}
if (!$err) {
$query = "INSERT INTO Images ( `imageId`, `imageCaption`,n";
$query .= " `imageDesc`, `imageFile`,n";
$query .= " `imageCat`)n";
$query .= " VALUES (0, '$caption', '$Desc',n";
$query .= " '$localName.jpg', '$category')";
$res = mysql_query($query);
if ($res) {
echo "Added image '$caption'<br>n";
} else {
echo "Image Storage error: " . mysql_error() . "<br>n";
}
}
mysql_close();
echo " <a href='$img'><img src='$tn'></a>n";
echo " <br><br>n";
echo " <a href='$Back'>n";
echo " Return to calling page</a>n";
echo " </body>n";
} else {
if (strncmp($type, "Delete", 6)) {
if (!$Name) $Name = "Add an";
else $Name = $Name . " an";
} else {
$Name = "Delete an";
}
if (!strncmp($type, "Delete", 6)) {
echo " <head>n";
echo " <title>$Name Image</title>n";
echo " </head>n";
echo " <body>n";
$query = "SELECT imageFile FROM Images ";
$query .= "WHERE `imageId`='$picId'";
//echo "query = $query<br>n";
if ($res = mysql_query($query)) {
$image = mysql_fetch_array($res);
extract($image);
$img = $photoDir . "/" . $imageFile;
$img_uri = Apache_lookup_uri($img);
$img_fn = $img_uri->filename;
$tn = $photoDir . "/Thumbs/" . $imageFile;
$tn_uri = apache_lookup_uri($tn);
$tn_fn = $tn_uri->filename;
$query = "DELETE FROM Images ";
$query .= "WHERE `imageId`='$picId'";
Echo "query = $query<br>n";
if (!($res = mysql_query($query))) {
echo "Failed to remove photo info from database";
return;
}
echo "Removing '$img_fn' and '$tn_fn'<br>n";
unlink($img_fn);
unlink($tn_fn);
echo " <br><br>n";
echo " <a href='$Back'>n";
echo " Return to calling page</a>n";
echo " </body>n";
}
return;
}
?>
<head>
<title><?php echo "$Name"?> Image</title>
<script language="JavaScript">
function OnSubmit(theForm) {
var theCat = theForm.category;
var catName = theForm.categoryName;
var ind = theCat.selectedIndex;
var opt = theCat.options[ind];
var theFile = theForm.theFile;
var newCat;
if (!theFile.value || (theFile.value == "")) {
alert("No file specified. " +
"Please specify a file to upload");
theFile.focus();
return false;
}
if (opt.value == "-1") {
newCat = prompt("Please enter the new Category name");
opt.text = newCat;
}
catName.value = opt.text;
return true;
}
</script>
</head>
<body onLoad="document.theForm.caption.focus()">
<h1><center><?php echo "$Name"?> Image</center></h1>
<br>
<?
$tmpName = tempnam($photoDir, "Photo");
$localName = basename($tmpName);
$img = "/photoDir/$localName";
$img_uri = apache_lookup_uri($img);
$img_fn = $img_uri->filename;
$tn = "/photoDir/Thumbs/$localName";
$tn_uri = apache_lookup_uri($tn);
$tn_fn = $tn_uri->filename;
?>
<form method="post" enctype="multipart/form-data"
name="theForm" onSubmit="return OnSubmit(this)">
<center>
<input type="hidden" name="MAX_FILE_SIZE" value=4194304>
<input type="hidden" name="submitted" value=1>
<table>
<tr>
<td align=right>Image Caption: </td>
<td><input type=text width=40 name=caption></td>
</tr>
<tr>
<td align=right valign=middle>Description: </td>
<td><textarea name=Desc
rows=4 cols=40 softwrap></textarea></td>
</tr>
<tr>
<td align=right>Select a category: </td>
<td><select name=category>
<?php OptArray($categories, 0) ?>
</select>
</td>
</tr>
<tr>
<td align=right>Select a file: </td>
<td><input type="file" name="theFile" size=15></td>
</tr>
</table>
<input type=hidden name=Back value="<?echo $Back?>">
<input type=hidden name=categoryName value="">
<input type=hidden name=imageNum value=0>
<input type="hidden" name="localName" size=40
value="<?php echo $localName?>"><br>
<input type="hidden" name="dlName" size=40 value="">
<br>
<br>
<input type="submit" name="submit" value="Load File">
</center>
</form>
<?
}
?>
</body>
</html>
Mod edit: Added code tags