473,569 Members | 2,788 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 1462
Atli
5,058 Recognized Expert Expert
Hey.

You can use the DirectoryIterat or 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
6872
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 Bennett
12
2661
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 print a sorted report of html files and their size. (a copy of the script is here: http://xahlee.org/_scripts/check_file_size.pl )
0
1134
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 in a SQL Server database. All this ain't a problem, but the problem is checking the size of logo because on the report the logo size is limited to...
5
12827
by: NewToCPP | last post by:
Is there any way I can check the size of the Memory allocated by "new"?
4
2185
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 { public byte MsgType; public uint Tag; public fixed byte ID; public fixed byte Val1;
8
21456
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 tables are? TIA ron
2
2280
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
15647
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 Html File Input control to using the new FileUpload control. Previously, I had set the maxRequestLength attribute in the machine.config file to...
7
12337
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 tedious job for me to calculate each table size manually. Thanks in advance, Kamalnath.V
3
8252
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 the file size; however, I'm not happy with this solution because my application is designed to work in multiple browsers and ActiveX is limited to...
0
7697
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.