Reputation: 11
I am using Ajax PHP to upload images to a folder, but I want to limit that space to 50 MB. I think I'm on the right track, but the code does not work for me. If you can help me.
I think the error should be in "if ($ size> 52428800) {"
Thank you
/*** 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');
}
}
Upvotes: 0
Views: 67
Reputation: 170
You are returning $size
on line 9. Everything below the return statement will be skipped.
If you move return $size
below the else, your code should work.
/*** 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;
}
Note: alert()
is not a PHP function, just in case you didn't create that function
Upvotes: 1