我正在使用Ajax PHP将图像上传到文件夹,但我想将该空间限制为50 MB。我认为我处在正确的轨道上,但是代码对我不起作用。如果您可以帮助我。
我认为错误应该在" if($ size> 52428800({"
谢谢
/*** Calling from ajax to add the gallery new an image****/
public function Addgallery() {
$size = 0;
$files= glob($directory.$folder_gallery.'/*');
foreach($files as $path){
is_file($path) && $size += filesize($path);
is_dir($path) && get_dir_size($path);
}
return $size;
if ($size > 52428800 ) {
echo alert("Your quota on disk does not allow the upload of images. Please erase images that you do not use.");
} else {
$this->_upload_file($this->_base_path .'/images/gallery/', array( '.png', '.jpg', '.jpeg', '.gif' ), 'addgallery');
}
}
您在第9行中返回$size
。
如果您将return $size
移动到其他方面,则您的代码应起作用。
/*** Calling from ajax to add the gallery new an image****/
public function Addgallery() {
$size = 0;
$files = glob($directory.$folder_gallery.'/*');
foreach($files as $path){
is_file($path) && $size += filesize($path);
is_dir($path) && get_dir_size($path);
}
if ($size > 52428800){
echo alert("Your quota on disk does not allow the upload of images. Please erase images that you do not use.");
} else {
$this->_upload_file($this->_base_path .'/images/gallery/', array( '.png', '.jpg', '.jpeg', '.gif' ), 'addgallery');
}
return $size;
}
注意:alert()
不是PHP功能,以防万一您没有创建该功能