Hi
I am designing a cms for my site. The user will be taking photos with a digital SLR camera and these photos need to be resized and uploaded to the webserver, see php script below. Although the photos are not very large - only 6megapixel and mostly around 1.6mb, the server easily runs low on
memory. So I get this error message on the remote server:
Fatal error: Allowed memory size of 16,777,216 bytes exhausted (tried to allocate 4000 bytes)
My localhost server seems to have a higher limit at 33,554,432 bytes.
Is there a way to allocate more memory in a script for this purpose?
Or any suggestions for a work-around?
PHP Code:
// Get file names
$orig_name = $_FILES['upl_file']['name'];
$temp_path = $_FILES['upl_file']['tmp_name'];
// Temp vars for file naming - shall come from form later
$avl_id = 3; $img_id = 99;
// Using date and time incl seconds for unique file name
$now = date(Y.m.d.'_'.G.i.s);
// Get the file extension, lower case
$ext = strtolower(end(explode(".", $orig_name)));
// New unique file name
$new_name = 'avlid'.$avl_id.'_'.$now.'_'.rand(10,99).'_imgid'.$img_id.'.'.$ext;
// Setting path for full size file and web image file
$path_fullsize = 'E:\data\avl_img_orig\\'.$new_name;
$path_web = 'avls/img/'.$new_name;
// Copy original to local drive outside site folder
copy($temp_path, $path_fullsize);
// RESIZING START:
// Load image with home-made function
$image = open_image($temp_path);
// Get original width and height and set new
$width = imagesx($image);
$height = imagesy($image);
$new_width = 800;
$new_height = $height * ($new_width/$width);
// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Save resized image
imagejpeg($image_resized, $path_web);
Bookmarks