aboutsummaryrefslogtreecommitdiff
path: root/actions/upload.php
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2009-05-16 22:38:41 +0000
committerCash Costello <cash.costello@gmail.com>2009-05-16 22:38:41 +0000
commit9f1c041a0c958a69bfb44e09d883628c2c97d00e (patch)
treef0f457b49812d0f0134fe75d80e4a5d20ffc21de /actions/upload.php
parentd1a369e67f5166a300cc47f1c41548c75b0b67d9 (diff)
downloadelgg-9f1c041a0c958a69bfb44e09d883628c2c97d00e.tar.gz
elgg-9f1c041a0c958a69bfb44e09d883628c2c97d00e.tar.bz2
checking approx size in memory to prevent WSOD on resize operations - this is using a very rough estimate
Diffstat (limited to 'actions/upload.php')
-rw-r--r--actions/upload.php17
1 files changed, 16 insertions, 1 deletions
diff --git a/actions/upload.php b/actions/upload.php
index bb59a45a1..8015a2ae8 100644
--- a/actions/upload.php
+++ b/actions/upload.php
@@ -66,11 +66,26 @@
continue;
}
- // make sure file does not exceed limit
+ // make sure file does not exceed memory limit
if ($sent_file['size'] > $maxfilesize) {
array_push($not_uploaded, $sent_file['name']);
continue;
}
+
+ // make sure the in memory image size does not exceed memory available - GD only
+ $imginfo = getimagesize($sent_file['tmp_name']);
+ $mem_required = 5 * $imginfo[0] * $imginfo[1];
+ $mem_avail = ini_get('memory_limit');
+ $mem_avail = rtrim($mem_avail, 'M');
+ $mem_avail = $mem_avail * 1024 * 1024;
+ $mem_avail = $mem_avail - memory_get_peak_usage() - 4194304; // 4 MB buffer
+ //error_log($mem_required);
+ //error_log($mem_avail);
+ if ($image_lib === 'GD' && $mem_required > $mem_avail) {
+ array_push($not_uploaded, $sent_file['name']);
+ trigger_error('Tidypics error: image memory size too large for resizing so rejecting', E_USER_WARNING);
+ continue;
+ }
//this will save to users folder in /image/ and organize by photo album
$prefix = "image/" . $container_guid . "/";