Web Hosting Talk







View Full Version : PHP exceeding site quota


jaschwa
09-07-2002, 10:52 PM
I have a customer that allows visitors to contribute text files to his site. The problem is that the PHP program he uses adds the file even if the site's quota has been exceeded. The fragment of code in use is:

if($filename = fopen("./unapproved/$filename", "w")) {
fputs($filename, $filebody);
fclose($filename);
}

First, is there a way I can have him modify this so that it operates within the limitations of the quota system?

Second, is there a way to compress/decompress the files on the fly?

Thanks

mind21_98
09-08-2002, 01:05 AM
Unfortunately, PHP runs as 'nobody', so unless Apache 2.0 becomes more widely used, that will be a limitation you will have to live with. :(

OldOne
09-09-2002, 11:24 AM
I am afraid, you will not be able to put limitations in his code.

CChard
09-09-2002, 01:22 PM
You can always ask him not to use it, and suggest a new one.

jaschwa
09-11-2002, 10:38 AM
What about using Zlib? According to http://www.php.net/manual/en/ref.zlib.php, it sounds like he could still use fopen function with the special prefix 'zlib://' to open the file and it would be gzipped on the fly.

Alturus
09-11-2002, 01:50 PM
Why not read the files in the directory, add up the sizes of the files, and if it's over a certain number, say 10 megs, it won't let you add it.

I use a similar scheme at http://supratest.ue3.net

When a user submits a photo, the size/name/etc gets recorded in the DB. A cumulative total of file sizes is kept and if they exceed 10 megs, then they get a message stating they're over their quota when they try and upload another file.

% of quota used is also displayed in their user-control section.

As I said, another non-DB way of doing this would be to read a directory, load the file sizes in an array, and add them up. If you do this as a 'check' before uploading the file, then depending on the size, they'll either be allowed to upload it, or denied.

Chr1s
09-14-2002, 03:25 PM
he could also just make store them inside mysql it wouldnt eat up all his hard drive space

jaschwa
09-15-2002, 08:21 PM
Thanks for the suggestions. I don't know who build the program he's using, but it doesn't keep track of file sizes.

I run a du command on his site and also checked his files in the other locations on the RaQ, and they total less than 50MB. Either the RaQ4 has problems adding or it uses an inefficient cluster size since most of the files are 1K or less. Keeping the textual data in the database would also prevent this type of inefficient disk space usage. Does mySQL have a string datatype capable of fields greater than 255?

Chr1s
09-15-2002, 09:40 PM
TEXT can hold a huge amount.. more than 255 chars..