我使用 Cakephp 作为我的框架。我在通过表单上传文件时遇到问题。我正在使用这个网站的上传器插件。
我的 php ini 文件有这段代码。
upload_max_filesize = 10M
post_max_size = 8M
这是来自 uploader.php --> 插件文件有
var $maxFileSize = '5M'; //default max file size
在我的 controller.php 文件中,我使用此代码在运行时将最大文件大小设置为 1 MB。
function beforeFilter() {
parent::beforeFilter();
$this->Uploader->maxFileSize = '1M';
}
在 uploader.php 中,我们执行这个...
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
预期结果:当我尝试上传大小为 2MB 的文件时,它不应该发生,因为 maxFileSize 在运行时为 1MB。所以上传应该失败。
问题是:但它正在上传。
地标 1 没有被执行。(在评论中)...地标 2 似乎不起作用...upload_max_filesize 没有从 maxFileSize 中获取值。
请帮助我...谢谢