我正在使用代码上传图片,将图片放入“调整大小”文件夹,调整图片大小,将图片移动到另一个文件夹,然后从“调整大小”文件夹中删除图片,不过我是我收到以下错误:
“致命错误:第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 };
此外,当我收到该错误时,图像卡在“调整大小”文件夹中..如果有人可以提供帮助,那就太棒了! :)
答案 0 :(得分:2)
您尝试调整目录中的所有图像,而不是在每个图像之后释放内存。尝试添加
imagedestroy($img);
imagedestroy($tmp_img);
首先。此外,请在完成后立即取消链接,而不是第二次遍历目录。