-1

Possible Duplicate:
Error: Allowed memory size of 67108864 bytes exhausted

I have a (multiple) file upload form on my website, and it works, but if I upload too much files (depends on file size I guess) I get that error. I know I can edit the memory_limit property in php.ini, but is their a way I can free up that memory with php?

I'm uploading some images, then they are resized and cropped to two images, and then saved in a directory and in a database.

Thanks

4

1 回答 1

1

当不再需要图像时(例如,当它被复制到不同的图像中时),可以使用 imagedestroy() 释放内存。这是一个例子:

function resize($width, $image,$path,$rand,$i) {
    $max_width = $width;
    $old_width = imagesx($image);
    $old_height = imagesy($image);
    $scale = ($max_width / $old_width);
    $new_width = ceil($scale*$old_width);
    $new_height = ceil($scale*$old_height);
    $new = imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($new, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);

    imagedestroy($image);

    return imagejpeg($new,"../../../bonangana/img/albums/$path/" . $rand . "_". str_replace(" ", "_", trim($_FILES['file']['name'][$i])));
}
于 2012-10-06T15:23:55.357 回答