Can anyone give me a quick guide on using memory resources? I know that I can limit the PHP memory limits in PHP.ini, and also through lines of code, for example:
ini_set("memory_limit","24M");
I have an image loading script that I am writing that uses a pretty cool PHP script called simpleImage, which can be found here: http://www.white-hat-web-design.co.uk/articles/php-image- resizing.php
I have a basic form that accepts jpg and png. I set the flash memory limit to 24 meters, believing that it would be high enough, but when I tried to upload a 3 MB image, I still got an excellent memory allocation error. Inclining the value to a more meaty 240M, and the script works fine (locally).
My script does this:
1) Accepts the loaded TMP image
2) Runs getimagesize () on the image to verify that it is a valid image.
3) Moving the temporary image to the destination destination directory.
4) Uploads an image using a simple image.
5) Resizes the image using a simple image.
6) Saves the modified image using a simple image script.
So, I assume that downloading / checking / resizing requires a bit larger than 24M. But I'm worried about what an acceptable distribution of memory limits will be. I would like users to be able to upload ~ 6 MB of images. Will it be very stressful on your medium dedicated servers?
script.. ??
if (!empty($_FILES)) {
ini_set("memory_limit","24M");
require_once('simpleImage.php');
require_once('db.php');
$tempFile = $_FILES['file']['tmp_name'];
$originalFile = $_FILES['file']['name'];
$extension = strtolower(end(explode(".", $originalFile)));
$targetFile = "path/to/directory/";
$validExtensions = array('jpg', 'jpeg', 'png');
if(in_array($extension, $validExtensions)) {
$validExtension = true;
} else {
$validExtension = false;
}
if(getimagesize($tempFile) == false) {
$validImage = false;
} else {
$validImage = true;
}
if($validExtension == true && $validImage == true) {
if(move_uploaded_file($tempFile,$targetFile)) {
$image = new SimpleImage();
$image->load($targetFile);
$image->resizeToWidth(500);
$image->save($targetFile);
}
}
}