[PHP] Directory Size Calculation...trying again!
Tried this earlier but have had no takersis it a no go? Please read on. Hello! I hope someone can help me with this...it's doin' my head in! Below I have a class I found for finding out directory sizes. What I have done is to get the username of each user and their create a directory path (based on their username - these directories do exist with subdirs). This works fine when I restrict the select statement to 1 user, but when selecting all, it generates an error for (nearly) all the users, namely, the ones with no contents in their directories. Thing is, just above the error, it prints what I want ( I think - haven't check it for accuracy yet). Any help or ideas on how to achieve this would be most helpful and appreciated!! (Win2K, PHP 4.1.1) The Code --- display_size(0); } else { while( $file = readdir($handle) ) { if($file != '.' and $file != '..') { is_dir("$dir/$file") ? $this->get_dir_size("$dir/$file", $size) : $size += filesize("$dir/$file"); } } if ($size < 1) { return $this->display_size(0); $handle =""; $size = "0"; } else { return $this->display_size($size); $handle =""; $size = "0"; } } } // File size calculations - for display. function display_size($file_size) { if($file_size >= 1073741824) { $file_size = round($file_size / 1073741824 * 100) / 100 . " Gb"; } elseif($file_size >= 1048576) { $file_size = round($file_size / 1048576 * 100) / 100 . " Mb"; } elseif($file_size >= 1024) { $file_size = round($file_size / 1024 * 100) / 100 . " Kb"; } else { $file_size = $file_size . " bytes"; } return $file_size; } } $sql = "SELECT * FROM FTPUsers"; $result = $dsn2->query( $sql ); if ( DB::isError( $result = $dsn2->query( $sql ) ) ) { echo DB::errorMessage( $result ); } else { while ( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { $dir = "F:/path/to/" . $row[Name] . ""; $d = new DirectoryInfo; echo "" . $row[Name] . " " . $d->get_dir_size($dir, $size); } } ?> --- Result --- User1 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User2 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User3 0 bytes User4 26.33 Mb Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User5 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User6 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 ... --- Thanks Simon H -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Directory Size
Hello! I hope someone can help me with this...it's doin' my head in! Below I have a class I found for finding out directory sizes. What I have done is to get the username of each user and their create a directory path (based on their username - these directories do exist with subdirs). This works fine when I restrict the select statement to 1 user, but when selecting all, it generates an error for (nearly) all the users, namely, the ones with no contents in their directories. Thing is, just above the error, it prints what I want ( I think - haven't check it for accuracy yet). Any help or ideas on how to achieve this would be most helpful and appreciated!! (Win2K, PHP 4.1.1) The Code --- display_size(0); } else { while( $file = readdir($handle) ) { if($file != '.' and $file != '..') { is_dir("$dir/$file") ? $this->get_dir_size("$dir/$file", $size) : $size += filesize("$dir/$file"); } } if ($size < 1) { return $this->display_size(0); $handle =""; $size = "0"; } else { return $this->display_size($size); $handle =""; $size = "0"; } } } // File size calculations - for display. function display_size($file_size) { if($file_size >= 1073741824) { $file_size = round($file_size / 1073741824 * 100) / 100 . " Gb"; } elseif($file_size >= 1048576) { $file_size = round($file_size / 1048576 * 100) / 100 . " Mb"; } elseif($file_size >= 1024) { $file_size = round($file_size / 1024 * 100) / 100 . " Kb"; } else { $file_size = $file_size . " bytes"; } return $file_size; } } $sql = "SELECT * FROM FTPUsers"; $result = $dsn2->query( $sql ); if ( DB::isError( $result = $dsn2->query( $sql ) ) ) { echo DB::errorMessage( $result ); } else { while ( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { $dir = "F:/path/to/" . $row[Name] . ""; $d = new DirectoryInfo; echo "" . $row[Name] . " " . $d->get_dir_size($dir, $size); } } ?> --- Result --- User1 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User2 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User3 0 bytes User4 26.33 Mb Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User5 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 User6 0 bytes Warning: OpenDir: Invalid argument (errno 22) in F:\OBS\WinPartnerWeb\www\partners\pa\obsWebsite\testsize.php on line 13 ... --- Thanks Simon H -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Dynamic Date Select and SQL
Thanks Rick But the SQL needs to work with MS Access AND MySQL through the PEAR DB Abstraction layer... I'm not saying it wont work with Access because I don't know yet...maybe it will, but there looks to be functions in there that may be MySQL specific. If I can do something like this it would be great...what I would like is to get the earliest month & year from the DB table then fill in the gaps between then and now, month by month to populate the SELECT BOX Options. Thanks Simon H > -Original Message- > From: Rick Emery [mailto:[EMAIL PROTECTED]] > Sent: 15 February 2002 16:06 > To: 'Simon H'; PHP General > Subject: RE: [PHP] Dynamic Date Select and SQL > Sensitivity: Confidential > > > If I understand your question, you are looking for the MYSQL sql > statement. > Based upon your info, I've found something like this example: > > mysql> describe a; > ++--+--+-+-+---+ > | Field | Type | Null | Key | Default | Extra | > ++--+--+-+-+---+ > | mydate | datetime | YES | | NULL| | > ++--+--+-+-+---+ > 1 row in set (0.04 sec) > > mysql> select * from a; > +-+ > | mydate | > +-+ > | 2002-01-01 12:00:00 | > | 2002-02-01 12:00:00 | > | 2002-03-01 12:00:00 | > | 2002-04-01 12:00:00 | > | 2002-05-01 12:00:00 | > | 2002-06-01 12:00:00 | > | 2002-07-01 12:00:00 | > +-+ > 7 rows in set (0.00 sec) > > mysql> select year(mydate)*100+month(mydate) as sel,mydate, > concat(left(monthname(mydate),3),' ',year(mydate)) as monyr > from a where mydate < now()+03; > ++-+--+ > | sel| mydate | monyr| > ++-+--+ > | 200201 | 2002-01-01 12:00:00 | Jan 2002 | > | 200202 | 2002-02-01 12:00:00 | Feb 2002 | > | 200203 | 2002-03-01 12:00:00 | Mar 2002 | > | 200204 | 2002-04-01 12:00:00 | Apr 2002 | > | 200205 | 2002-05-01 12:00:00 | May 2002 | > ++-+--+ > 5 rows in set (0.05 sec) > > -Original Message- > From: Simon H [mailto:[EMAIL PROTECTED]] > Sent: Friday, February 15, 2002 6:32 AM > To: PHP General > Subject: [PHP] Dynamic Date Select and SQL > Sensitivity: Confidential > > > I have a problem I hope someone can help me with... > > Firstly I have an SQL Query with a "WHERE dateMonthAndYear = $month1" > > Already this shows part of what I'm trying to do. The date > format in the DB > is "-MM-DD HH:MM:SS". > > Now I need to dynamically generate a pulldown of months... > > The range of months in the pulldown are historical, so the last > month would > be the current month (which should also be the SELECTED option). > The first > month would be a fixed date, say Jan 2002. > > The value of the options would probably be like so: > > // <<--- Jump Menu > Feb > 2002 > // <<--- Current Month (SELECTED) >value="$PHP_SELF?month1=$first_month">$first_month_text > // <<--- First Month in range >value="$PHP_SELF?month1=$subsequent_month1">$subsequent_month1_tex > t > // <<--- Other months in range > . > // <<--- Other months in range > Feb > 2002 > // <<--- Current Month > ALL > // <<--- Empty value > will show all > > > I guess the question is, how do I dynamically create the select, based on > the above spec (or make $first_month, the first month available in the SQL > Query i.e. get the earliest month from the Query), then do the > select using > ONLY the month and year information. > > I can do most of the bits in between, just do know how to do the dynamic > select for this particular application, or get the date into the SQL where > ONLY the month and year are relevant. > > I am using Pear DB and need this to work on MySQL and Access > through Pear so > the SQL needs to be quite standard. The above code is not syntaxed > properlyjust meant for readability. > > Any ideas are much appreciated as I don't even know where to > start with this > one. > > Thanks > > Simon H > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic Date Select and SQL
I have a problem I hope someone can help me with... Firstly I have an SQL Query with a "WHERE dateMonthAndYear = $month1" Already this shows part of what I'm trying to do. The date format in the DB is "-MM-DD HH:MM:SS". Now I need to dynamically generate a pulldown of months... The range of months in the pulldown are historical, so the last month would be the current month (which should also be the SELECTED option). The first month would be a fixed date, say Jan 2002. The value of the options would probably be like so: // <<--- Jump Menu Feb 2002 // <<--- Current Month (SELECTED) $first_month_text // <<--- First Month in range $subsequent_month1_text // <<--- Other months in range . // <<--- Other months in range Feb 2002 // <<--- Current Month ALL // <<--- Empty value will show all I guess the question is, how do I dynamically create the select, based on the above spec (or make $first_month, the first month available in the SQL Query i.e. get the earliest month from the Query), then do the select using ONLY the month and year information. I can do most of the bits in between, just do know how to do the dynamic select for this particular application, or get the date into the SQL where ONLY the month and year are relevant. I am using Pear DB and need this to work on MySQL and Access through Pear so the SQL needs to be quite standard. The above code is not syntaxed properlyjust meant for readability. Any ideas are much appreciated as I don't even know where to start with this one. Thanks Simon H -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Yet another regex question
Thanks James This is excellent. If you don't mind digging out your functions, I'd much appreciate it... > Hello, Simon.... > > "Simon H" wrote in message... > > I'm trying to validate an input form, for database INSERT/UPDATE. I'm > > looking for a couple of Techniques and I cant seem to find examples > > anywhere: > > > > 1. Validate Alpha Text with spaces, such as NAME, CITY, STATE, but limit > the > > length of each one separately, and remove unwanted characters like > > '@!"£$%^&*() etc that might mess with the SQL. > > Alright, clearup before you insert. That's my first bit of advice. > Here's a function for you. > > function ClearUnwanteds($string) { > $string = preg_replace("/[^a-zA-Z0-9 ]/", $string); > $string = trim($string); > return $string; > } > > This will replace (when invoked, like this: $string = > ClearUnwanteds($string) ) the characters you don't want, and then trim the > string. Then you can do: > > if (strlen($string) < /*enter minimum characters*/) { > // error > } > > > 2. As above but alphanumeric with spaces etc. for say ADDRESS1 ADDRESS2 > > POSTCODE, etc. > > Hmm.. isn't that what you wanted for your previous problem? The previous question was for alpha only, no numeric ...names dont have numbers, but addresses usually do. > > > 3. Validate DATE/TIME input to DD-MM- HH:MM:SS or D-M- H:M:S, or > any > > combination, but only allow valid dates and times, or as close to it as > > possible. > > You should pick a format, and stick to it, then form a function around the > format you've chosen - or look up some classes available for use > on the net. > Since you're storing the data in a MySQL database, you may as > well check the > date in the format it's stored in your db in the date (-MM-DD) or > datetime (-MM-DD HH:MM:SS) formats MySQL uses I would go > for select > boxes with the day, month and year specified, then use something like > checkdate() to check the date on these variables, then "merge" them > (can't think of a better word) to form your date - i.e. > > if (CheckDate($month, $day, $year)) { > // -- if ok, $date = $year . "-" . $month . "-" . $day; > } else { > // failure > } > > I have formed some functions that I've made available (somewhere), if you > need them I can probably drag them out and give you the urls. I'd got kinda mixed up there on the date thing...lol. I have a javascript date picker thingy, but unfotunately it drops leading zeros on the dates and times. I think, however, your suggestion if pulldowns is much safer, but the date will be for MySQL or MS Access. I think -MM-DD HH:MM:SS, as you suggested would be the answer, and I'll try to add the time into the $date variable. > > > 4. Validate MONEY input...numeric with 2 decimal places only. > > What currency? You're using a UK email address, but you've specified > "STATE" in one of your other regex "wanteds", which is more typical of the > US address format. The currency is irrelevent here (although will UK£). I just want the 2 decimal places money format. I have STATE above because thats what the field is in the databaseOn display it says state/county. > > > Also, what is the best way to allow some fields to be empty, like > ADDRESS2, > > but if they have data, then validate it. > > if (!emtpy($field)) { > // perform validation. > } > > ??? > > > I've tried several times to do these myself using eregi, but when I test > it, > > the validation fails in some way...I'm shooting in the dark > tho, and don't > > really understand regex just yet, or probably the majority of > PHP for that > > matter. > > Well, ok. But that's what you're here for, right? :) Truethanks!! > > > Thankfully I've got an email one... it was easy to find, since > that's what > > all examples are geared for. My application is for updating a DB with > SQL, > > and I cant find anything suitable. > > Then your'e looking in the wrong places (and more specifically, looking at > things from the wrong perspective - regex's can be applied to pretty much > anything (though, there are occassions when using them is overkill))! > > > If there is any other advice for data input into DB's regarding > security, > > I'd really to hear it. > > bvr's advice is good - read up on what he's suggested. :) Oh, and > there are > the manual entries (for which I've forgotten the addresses). > > Good luck! > > ~James > Thanks again James! Simon H -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Yet another regex question
Thanks bvr This is good to know, but I still need some validation with my particular application, as below. Thanks for your time. Simon H > -Original Message- > From: bvr [mailto:[EMAIL PROTECTED]] > Sent: 04 February 2002 17:44 > To: php-general; Simon H > Subject: Re: [PHP] Yet another regex question > > > > > Hi, > > To prevent user input from messing with your query you just need to > escape the characters used to delimit query values. > > MySQL for example uses ' (single quote) to delimit values so you should > use addslashes() on all values. > > This will make inserting values containing the ' character work > and prevent > user input from manipulating your script to run arbitrary queries > on your DB server. > > The practical thing about MySQL is that it accepts quote > delimited values even for > integer fields. However, if you want to make a 'db safe' integer > you can use $var = (int)$var; > > For more advanced input validation, regular expressions can be > very adequate but I'd > recommend separating this from previous mentioned 'escaping' > which is simply needed > for your DB to function properly and safe. > > greets, > bvr. > > > > > > On Mon, 4 Feb 2002 17:18:20 -, Simon H wrote: > > >I'm trying to validate an input form, for database INSERT/UPDATE. I'm > >looking for a couple of Techniques and I cant seem to find examples > >anywhere: > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Yet another regex question
I'm trying to validate an input form, for database INSERT/UPDATE. I'm looking for a couple of Techniques and I cant seem to find examples anywhere: 1. Validate Alpha Text with spaces, such as NAME, CITY, STATE, but limit the length of each one separately, and remove unwanted characters like '@!"£$%^&*() etc that might mess with the SQL. 2. As above but alphanumeric with spaces etc. for say ADDRESS1 ADDRESS2 POSTCODE, etc. 3. Validate DATE/TIME input to DD-MM- HH:MM:SS or D-M- H:M:S, or any combination, but only allow valid dates and times, or as close to it as possible. 4. Validate MONEY input...numeric with 2 decimal places only. Also, what is the best way to allow some fields to be empty, like ADDRESS2, but if they have data, then validate it. I've tried several times to do these myself using eregi, but when I test it, the validation fails in some way...I'm shooting in the dark tho, and don't really understand regex just yet, or probably the majority of PHP for that matter. Thankfully I've got an email one... it was easy to find, since that's what all examples are geared for. My application is for updating a DB with SQL, and I cant find anything suitable. If there is any other advice for data input into DB's regarding security, I'd really to hear it. Thanks in advance for any help at all! Simon H -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ereg(i) for form input validation for SQL - tutorial?
Does anyone know of a good tutorial for using ereg and eregi to validate standard fields for SQL input (i'm using PearDB). Typically the type of validation that I think I need would be, firstly to detect invalid characters, or special characters, or things that can screw up the SQL Query. Others would be the alpha only, string lengths, email address, dates and times, phone numbers. These are standard items in a lot of systems...surely there's a tutorial out there somewhere, or a sample script or something. I've only just discovered regex, so its all a bit h at the moment. Any links for tutorials or sample scripts would be much appreciated. Thanks Simon H -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Calculate Directory Size
smime.p7m Description: application/pkcs7-mime