473,503 Members | 8,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check folders size and set the size limited

1 New Member
helloo guy i want make script

to check the folder size

and set the folder max size 1GB

i try to make it
im useing linux debian


root@de1:/home/unixuser/OGP_User_Files# dir
user1 user2


===========

the problem the users can upload more then 1 GB

i want set max user folder to 1 GB only

how i make this with php?

im new in php and linux


my code have problems

i want check the folders size in dirname OGP_User_Files
and if the folder size 1 GB chmod it to 444
Apr 17 '13 #1
3 1457
Atli
5,058 Recognized Expert Expert
Hey.

You can use the DirectoryIterator class to go over every file in a directory and find their sizes. Like this:
Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Returns the total number of bytes for all files under the given directory.
  3.  * @param string $path Path to the directory.
  4.  * @return int
  5.  */
  6. function getDirectorySize($path) {
  7.     $size = 0;
  8.     $directory = new DirectoryIterator($path);
  9.     foreach ($directory as $file) {
  10.         if ($file->isFile()) {
  11.             $size += $file->getSize();
  12.         }
  13.         else if (!$file->isDot() && $file->isDir()) {
  14.             $size += getDirectorySize($file->getPathname());
  15.         }
  16.     }
  17.  
  18.     return $size;
  19. }
  20.  
However, if you are making some sort of file sharing/storing site with multiple users, each of which can store an X amount of data, then I wouldn't recommend this approach. It would be easier to manage this if you didn't store the user files separately, but simply saved them all in a common place and stored the paths to the files in a database. Then you could calculate how much space a user is using by doing a database query instead of having to read it from the actual hard drive.
Apr 21 '13 #2
Dormilich
8,658 Recognized Expert Moderator Expert
if there are subfolders to check, the recursive version is a bit more convenient
Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Returns the total number of bytes for all files under the given directory.
  3.  * @param string $path Path to the directory.
  4.  * @return int
  5.  */
  6. function getDirectorySize($path) {
  7.     $size = 0;
  8.     $directory = new RecursiveIteratorIterator(
  9.         new RecursiveDirectoryIterator(
  10.             $path, FilesystemIterator::SKIP_DOTS
  11.         )
  12.     );
  13.  
  14.     foreach ($directory as $file) {
  15.         $size += $file->getSize();
  16.     }
  17.  
  18.     return $size;
  19. }
Apr 23 '13 #3
Atli
5,058 Recognized Expert Expert
O yea, there was a recursive version of that iterator. Nice catch. I completely overlooked it.
Apr 24 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6870
by: Pete Bennett | last post by:
Folks, I want to allow people to upload files to my site. I wondered, is there a way in Javascript to limit the size of the file they are able to submit? Cheers -- Kind Regards, Pete...
12
2655
by: Xah Lee | last post by:
would anyone like to translate the following perl script to Python or Scheme (scsh)? the file takes a inpath, and report all html files in it above certain size. (counting inline images) also...
0
1124
by: Piedro | last post by:
Hi group, I've got a,in my opnion, difficult problem. I've made a form on which the user can select a logo which he wants to print on a crystal reports report. The logo is saved as a BLOB field...
5
12822
by: NewToCPP | last post by:
Is there any way I can check the size of the Memory allocated by "new"?
4
2177
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry {...
8
21441
by: Ron | last post by:
Hi all, How do I determine the size of the tables I'm using? I looked under properties and it's not there. The book I just browsed said table is limited to 1GB. How do I find out what size my...
2
2277
by: yonthebeach | last post by:
hi, i have an upload mechanism on my website and want to check the filesize on the client size. is this possible? thanks yavuz bogazci
12
15623
by: Phil Z. | last post by:
After migrating an ASP.NET 1.1 application to 2.0 we were getting "Cannot access a closed file" errors when uploading. I found a number of post on the subject and have since moved from using an...
7
12321
by: Gladiator | last post by:
Hi , I was trying to find the size of a schema (Size of all the tables in a schema). Can some one tell me an easy way to do this. There are more than 200 tables in my schema and it is very...
3
8246
Frinavale
by: Frinavale | last post by:
Hi there! I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript. I have seen suggested solutions using an ActiveX control to check...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.