Web Design Forum: allocating members server space - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

allocating members server space Rate Topic: -----

#1 User is online   adamsmith 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 336
  • Joined: 04-June 11
  • Reputation: 9
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 05 January 2012 - 06:21 PM

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???
0

#2 User is offline   Sogo7 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 421
  • Joined: 02-February 11
  • Reputation: 42
  • Gender:Male
  • Location:Camarthen
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

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.
0

#3 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 05 January 2012 - 09:30 PM

View PostSogo7, 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)


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.
1

#4 User is online   adamsmith 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 336
  • Joined: 04-June 11
  • Reputation: 9
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

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?
0

#5 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,818
  • Joined: 03-January 10
  • Reputation: 266
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 06 January 2012 - 12:38 AM

View Postadamsmith, 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 :)
0

#6 User is online   adamsmith 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 336
  • Joined: 04-June 11
  • Reputation: 9
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 06 January 2012 - 10:38 AM

it worked perfect for what i wanted, i'm gonna start learning them
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users