Cakephp file upload problem.
- by vatismarty
I am using Cakephp as my framework. I have a problem in uploading my files through a form. I am using an Uploader plugin from THIS website.
My php ini file has this piece of code.
upload_max_filesize = 10M
post_max_size = 8M
this is from uploader.php -- plugin file has
var $maxFileSize = '5M'; //default max file size
In my controller.php file, i use this code to set max file size as 1 MB at runtime.
function beforeFilter() {
parent::beforeFilter();
$this->Uploader->maxFileSize = '1M';
}
In the uploader.php, we perform this ...
if (empty($this->maxFileSize)) {
$this->maxFileSize = ini_get('upload_max_filesize'); //landmark 1
}
$byte = preg_replace('/[^0-9]/i', '', $this->maxFileSize);
$last = $this->bytes($this->maxFileSize, 'byte');
if ($last == 'T' || $last == 'TB') {
$multiplier = 1;
$execTime = 20;
} else if ($last == 'G' || $last == 'GB') {
$multiplier = 3;
$execTime = 10;
} else if ($last == 'M' || $last == 'MB') {
$multiplier = 5;
$execTime = 5;
} else {
$multiplier = 10;
$execTime = 3;
}
ini_set('memore_limit', (($byte * $multiplier) * $multiplier) . $last);
ini_set('post_max_size', ($byte * $multiplier) . $last); //error suspected here
ini_set('upload_tmp_dir', $this->tempDir);
ini_set('upload_max_filesize', $this->maxFileSize); //landmark 2
EXPECTED RESULT:
When i try uploading a file that is 2MB of size, it shouldn't take place because maxFileSize is 1MB at run time. So upload should fail.
THE PROBLEM IS :
But it is getting uploaded.
Landmark 1 does not get executed. (in comments)... land mark 2 does not seem to work...
upload_max_filesize does not get the value from maxFileSize.
Please help me... thank you