Well, I've searched around and found a lot of people poking
around at solutions, but I was unable to find one for me.
Here is the problem.
I can upload small pictures, but large pictures I get this error:
Fatal error: Allowed memory size of 10485760 bytes
exhausted at (null):0 (tried to allocate 8320 bytes) in
/home/virtual/site3/fst/var/www/html/resources/integral.php on line 1133
which is where I'm autothumbnailing the image.
When I upload something much larger I get a pop-up:
Document contains no data.
in Firefox and in IE I get:
Page cannot be displayed.
I have an upload class I'll show below. It was written by
somebody else but heavily edited by me. I know this
is a lot to ask, but upload handling is such a pain in
the butt. Please take a look and let me know what you
think might be causing the problem.
// Vars declared before class
$imagepath = $htmlpath."images/";// Path to site's images directory (not uploaded images or thumbnails)
$imagepath_uploaded = $imagepath."uploaded/";// Path to directory for uploading fullsize images
$imagepath_thumbs = $imagepath."thumbs/";// Path to directory for putting uploaded image thumbnails
$upload_path = $htmlpath."uploads/";// Path for uploading all non-image files
$allowed_upload_extensions = array('gif','jpg','jpeg','png','mp3','mpg','mpeg','avi','mov','asf','wmv','asx','rtf');
$max_upload_filesize = 40000000;
$max_thumb_width = 100;
$max_thumb_height = 100;
/****************************************
| File Upload |
****************************************/
class File_upload {
var $maxupload_size;
var $errors;
var $isPosted;
var $_FILES;
var $isImage;
function file_upload() {
global $_FILES;
global $max_upload_filesize;
$this->_FILES = $_FILES;
if (empty($_FILES)) {
$this->isPosted = false;
} else {
$this->isPosted = true;
}
$this->maxupload_size = $max_upload_filesize;
}
function display_form () {
echo ("<!-- Begin Upload Form Display -->
<form action=\"".$PHP_SELF."\" enctype=\"multipart/form-data\" method=\"post\">
<input type=\"file\" name=\"file1\"></input>
<input type=\"text\" name=\"newname\"></input>
<input type=\"submit\" value=\"Upload\"></input>
</form>
<!-- End Upload Form Display -->
");
}
function saveAs($filename, $directory, $tempfile, $overwrite,$mode=0777) {
global $file_parts;
global $srcImage;
global $imagepath_uploaded;
global $imagepath_thumbs;
global $max_thumb_width;
global $max_thumb_height;
global $allowed_upload_extensions;
global $text_over_image;
file_determine_parts('temp',$tempfile);
foreach ($allowed_upload_extensions as $ext_holder) {
if ($file_parts['extension'] == $ext_holder) {
$ext_allowed = true;
if ($file_parts['extension'] == "gif" || $file_parts['extension'] == "jpg" || $file_parts['extension'] == "jpeg" || $file_parts['extension'] == "png") {
$this->isImage = 1;
} else {
$this->isImage = 0;
}
if ($this->_FILES[$tempfile]['size'] < $this->maxupload_size && $this->_FILES[$tempfile]['size'] >0) {
$noerrors = true;
$tempName = $this->_FILES[$tempfile]['tmp_name'];
$all = $directory.$filename;
if (file_exists($all)) {
if ($overwrite) {
@unlink($all) || $noerrors=false; $this->errors = "Upload class saveas error: unable to overwrite ".$all."<BR>";
if ($this->isImage == 1) {
if ($file_parts['extension'] == "gif") {
$srcImage = imageCreateFromGif($tempName);
} elseif ($file_parts['extension'] == "jpeg" || $file_parts['extension'] == "jpg") {
$srcImage = imageCreateFromJpeg($tempName);
} else {
$srcImage = imageCreateFromPNG($tempName);
}
$srcSize = getImageSize($tempName);
$red = imagecolorallocate($srcImage, 128, 0, 0);
// for 2 lines - imageString($srcImage,4,($srcSize[0] - 150),($srcSize[1] - 35),$text,$red);
imageString($srcImage,4,($srcSize[0] - 150),($srcSize[1] - 25),$text_over_image,$red);
if ($file_parts['extension'] == "gif") {
$file_parts['extension'] = substr_replace($file_parts['extension'], 'jpg', -3);
$filename = substr_replace($filename, 'jpg', -3);
imageJpeg($srcImage,$imagepath_uploaded.$filename,100);
} elseif ($file_parts['extension'] == "jpg" || $file_parts['extension'] == "jpeg") {
imageJpeg($srcImage,$imagepath_uploaded.$filename,100);
} else {
imagePNG($srcImage,$imagepath_uploaded.$filename);
}
$this->image_createThumb($imagepath_uploaded.$filename,$imagepath_thumbs.$filename,$max_thumb_width,$max_thumb_height,$text_over_image);
} else {
@move_uploaded_file($tempName,$all) || $noerrors=false; $this->errors .= "Upload class saveas error: unable to copy to ".$all."<BR>";
@chmod($all,$mode) || $noerrors=false; $this->errors .= "Upload class saveas error: unable to copy to".$all."<BR>";
}
} else {
$noerrors=false; $this->errors = "Upload class saveas error: File ".$all." already exists. Please choose another name.<br>";
}
} else {
if ($this->isImage == 1) {
if ($file_parts['extension'] == "gif") {
$srcImage = imageCreateFromGif($tempName);
} elseif ($file_parts['extension'] == "jpeg" || $file_parts['extension'] == "jpg") {
$srcImage = imageCreateFromJpeg($tempName);
} else {
$srcImage = imageCreateFromPNG($tempName);
}
$srcSize = getImageSize($tempName);
$red = imagecolorallocate($srcImage, 128, 0, 0);
// To add 2 lines of text - imageString($srcImage,4,($srcSize[0] - 150),($srcSize[1] - 35),$text,$red);
imageString($srcImage,4,($srcSize[0] - 150),($srcSize[1] - 25),$text_over_image,$red);
if ($file_parts['extension'] == "gif") {
$file_parts['extension'] = substr_replace($file_parts['extension'], 'jpg', -3);
$filename = substr_replace($filename, 'jpg', -3);
imageJpeg($srcImage,$imagepath_uploaded.$filename,100);
} elseif ($file_parts['extension'] == "jpg" || $file_parts['extension'] == "jpeg") {
imageJpeg($srcImage,$imagepath_uploaded.$filename,100);
} else {
imagePNG($srcImage,$imagepath_uploaded.$filename);
}
$this->image_createThumb($imagepath_uploaded.$filename,$imagepath_thumbs.$filename,$max_thumb_width,$max_thumb_height);
} else {
@move_uploaded_file($tempName,$all) || $noerrors=false; $this->errors = "Upload class saveas error: unable to copy to ".$all."<BR>";
@chmod($all,$mode) || $noerrors=false; $this->errors .= "Upload class saveas error: unable to change permissions for: ".$all."<BR>";
}
}
return $noerrors;
} elseif ($this->_FILES[$tempfile]['size'] > $this->maxupload_size) {
$this->errors = "File size exceeds maximum file size of ".$this->maxuploadsize." bytes";
return false;
} elseif ($this->_FILES[$tempfile]['size'] == 0) {
$this->errors = "File size is 0 bytes";
return false;
}
}
}
if ($ext_allowed != true && $this->isPosted == true) {
$this->errors = "File extension not allowed";
}
}
function image_createThumb($src,$dest,$maxWidth,$maxHeight,$quality=90) {
if (file_exists($src) && isset($dest)) {
// path information
$destInfo = pathInfo($dest);
// source image size
$srcSize = getImageSize($src);
// calculate destination image size
$srcRatio = $srcSize[0]/$srcSize[1]; // width/height ratio
$destRatio = $maxWidth/$maxHeight;
if ($destRatio > $srcRatio) {
$destSize[1] = $maxHeight;
$destSize[0] = $maxHeight*$srcRatio;
} else {
$destSize[0] = $maxWidth;
$destSize[1] = $maxWidth/$srcRatio;
}
// path rectification
if ($destInfo['extension'] == "gif") {
$dest = substr_replace($dest, 'jpg', -3);
}
// true color image, with anti-aliasing
$destImage = imageCreateTrueColor($destSize[0],$destSize[1]);
imageAntiAlias($destImage,true);
// src image
switch ($srcSize[2]) {
case 1:
$srcImage = imageCreateFromGif($src);
break;
case 2:
$srcImage = imageCreateFromJpeg($src);
break;
case 3:
$srcImage = imageCreateFromPng($src);
break;
default:
return false;
break;
}
// Actually resampling the image
imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]);
// Generating output image
switch ($srcSize[2]) {
case 1:
case 2:
imageJpeg($destImage,$dest,$quality);
break;
case 3:
imagePng($destImage,$dest);
break;
}
return true;
} else {
return false;
}
}
function getFilename($tempfile) {
return $this->_FILES[$tempfile]['name'];
}
function getFileMimeType($tempfile) {
return $this->_FILES[$tempfile]['type'];
}
function getFileSize($tempfile) {
return $this->_FILES[$tempfile]['size'];
}
}