我使用将上载的图像,把图像中的“调整大小”文件夹,调整图像的大小,图像移动到另一文件夹中的代码,然后从“调整大小”文件夹中删除的图像,但是我m到处以下错误:

“的致命错误:用尽33554432个字节允许存储器大小(试图分配14172个字节)中/home/photogra/public_html/administrator/components/com_gallery/admin.gallery.php线649

在图像,甚至没有大的! (例如,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         };

此外,当我得到这个错误,图像被陷在“调整”文件夹中,如果还有人能帮忙,那简直是太棒了! :)

有帮助吗?

解决方案

您正在尝试调整目录中的所有的图像,而无需每一次之后释放内存。尝试添加

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

对于初学者。此外,一旦断开链接的图片作为你用它做而不是通过目录遍历第二次。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top