0

我正在使用将上传图像的代码,将图像放入“resize”文件夹,调整图像大小,将图像移动到另一个文件夹,然后从“resize”文件夹中删除图像,但是我得到了以下错误:

致命错误:第 649 行 /home/photogra/public_html/administrator/components/com_gallery/admin.gallery.php 中允许的内存大小为 33554432 字节已用尽(尝试分配 14172 字节)

图片也不大!(例如 265kb)

这是我正在使用的代码(带有行号):

635         move_uploaded_file($_FILES['image']['tmp_name'],$mainframe->getCfg( 'absolute_path' ) ."/virtualgallery/images/resize/$newname");
636         
637         /* resize images - width 600px */   
638         $docRoot = $GLOBALS['mosConfig_absolute_path'];
639         $pathToImages = $docRoot.'/virtualgallery/images/resize/';
640         $pathToThumbs = $docRoot.'/virtualgallery/images/';
641         $thumbHeight = 600;
642         
643         $dir = opendir( $pathToImages );
644         while (false !== ($fname = readdir( $dir ))) {
645             $info = pathinfo($pathToImages . $fname);
646             if ( strtolower($info['extension']) == 'jpg' ) {
647                 $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
648                 $width = imagesx( $img );
649                 $height = imagesy( $img );
650                 $new_width = floor( $width * ( $thumbHeight / $height ) );
651                 $new_height = $thumbHeight;
652                 $tmp_img = imagecreatetruecolor( $new_width, $new_height );
653                 imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
654                 imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
655             };
656         };
657         closedir( $dir );
658         
659         /* delete file(s) from resize folder */
660         $dir = $docRoot.'/virtualgallery/images/resize/';
661         foreach(glob($dir.'*.*') as $v) {
662             unlink($v);
663         };

另外,当我收到该错误时,图像会卡在“调整大小”文件夹中。如果有人可以提供帮助,那就太好了!:)

4

1 回答 1

2

您正在尝试调整目录中所有图像的大小而不释放每个图像之后的内存。尝试添加

imagedestroy($img);
imagedestroy($tmp_img);

对于初学者。此外,在完成后立即取消链接图像,而不是再次遍历目录。

于 2009-07-08T00:42:27.523 回答