How would I go about allocating x-amount of server space to each user's email and uploads etc?
I don't know if this would be PHP, .htaccess or whatever???
Page 1 of 1
allocating members server space
#2
Posted 05 January 2012 - 07:48 PM
PHP could be used to create a folder for holding each users individual files
then the filesize command can be looped through the contents and
adds them all up. (sadly there is no command for actualy getting a folders size)
If your running a Linux server try this
http://www.go4expert...hread.php?t=290
similiar examples are around for those on Windows servers.
One the SQL gurus here should be able to tell you how the same trick is done with a database storage setup.
then the filesize command can be looped through the contents and
adds them all up. (sadly there is no command for actualy getting a folders size)
If your running a Linux server try this
http://www.go4expert...hread.php?t=290
similiar examples are around for those on Windows servers.
One the SQL gurus here should be able to tell you how the same trick is done with a database storage setup.
#3
Posted 05 January 2012 - 09:30 PM
Sogo7, on 05 January 2012 - 07:48 PM, said:
PHP could be used to create a folder for holding each users individual files
then the filesize command can be looped through the contents and
adds them all up. (sadly there is no command for actualy getting a folders size)
then the filesize command can be looped through the contents and
adds them all up. (sadly there is no command for actualy getting a folders size)
Why do people on this forum seem to totally ignore SPL - some of the functions are soooooo useful and easy to use?
It' so useful for getting things like a directory size - in a couple of lines of code:
$dir = 'img'; $size = 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $file) {
$size += $file->getSize();
}
echo $size;
The above code will recursively loop through sib folders too - useful if users can create their own directories. Things like this soon become pretty messy (and slow) using opendir, filesize etc. Less code = good
You could change this to ignore sub folders too:
$dir = 'img'; $size = 0;
foreach(new DirectoryIterator($dir) as $file) {
if($file->isFile())
$size += $file->getSize();
}
echo $size;
There are some methods using glob that you could do in a single line of code, but they are quite inefficient and requires several array_* functions.
#4
Posted 05 January 2012 - 10:10 PM
I'll give that a try thank you.
Inside the forloop where it says 'RecursiveIteratorIterator', is that something you've made or is it something built into PHP?
Is there a better way that is more 'user friendly' than limiting file size?
Inside the forloop where it says 'RecursiveIteratorIterator', is that something you've made or is it something built into PHP?
Is there a better way that is more 'user friendly' than limiting file size?
#5
Posted 06 January 2012 - 12:38 AM
adamsmith, on 05 January 2012 - 10:10 PM, said:
Inside the forloop where it says 'RecursiveIteratorIterator', is that something you've made or is it something built into PHP?
Standard PHP LIbrary (SPL) - they are a set of classes compiled with PHP that are meant to solve everyday problems. E.g. some of the array overloading classes are very useful.
I find some of them very useful and haven't every used a couple of em at all
#6
Posted 06 January 2012 - 10:38 AM
it worked perfect for what i wanted, i'm gonna start learning them
- ← PHP form - what do I do with it?
- Server Side (PHP, Databases, ASP.NET, etc)
- How would you approach this? Wordpress →
Share this topic:
Page 1 of 1
Help

















