Skip to content
Browse files

Closes #43

  • Loading branch information...
1 parent 2beb261 commit 41113fa3a439f502970b7c01abbe864efe5344e9 @valums valums committed Oct 18, 2010
Showing with 26 additions and 3 deletions.
  1. +26 −3 server/php.php
View
29 server/php.php
@@ -64,11 +64,13 @@ class qqFileUploader {
private $sizeLimit = 10485760;
private $file;
- function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){
+ function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){
$allowedExtensions = array_map("strtolower", $allowedExtensions);
$this->allowedExtensions = $allowedExtensions;
- $this->sizeLimit = $sizeLimit;
+ $this->sizeLimit = $sizeLimit;
+
+ $this->checkServerSettings();
if (isset($_GET['qqfile'])) {
$this->file = new qqUploadedFileXhr();
@@ -79,6 +81,27 @@ function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){
}
}
+ private function checkServerSettings(){
+ $postSize = $this->toBytes(ini_get('post_max_size'));
+ $uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
+
+ if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit){
+ $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
+ die("{'error':'increase post_max_size and upload_max_filesize to $size'}");
+ }
+ }
+
+ private function toBytes($str){
+ $val = trim($str);
+ $last = strtolower($str[strlen($str)-1]);
+ switch($last) {
+ case 'g': $val *= 1024;
+ case 'm': $val *= 1024;
+ case 'k': $val *= 1024;
+ }
+ return $val;
+ }
+
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
@@ -131,7 +154,7 @@ function handleUpload($uploadDirectory, $replaceOldFile = FALSE){
// list of valid extensions, ex. array("jpeg", "xml", "bmp")
$allowedExtensions = array();
// max file size in bytes
-$sizeLimit = 6 * 1024 * 1024;
+$sizeLimit = 10 * 1024 * 1024;
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload('uploads/');

0 comments on commit 41113fa

Please sign in to comment.
Something went wrong with that request. Please try again.