SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Maryland
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reading files in php

    Ok, heres my delima. I wan to have a field in my database that shows a user here current directory size. Preferably putting this size into a percentage of their max space. This is what i thought of:

    1. Run a shell script that gathers the directory space usage per user.(unix environment)

    2. Have php script read this file for print out to the webpage.(Or is there a function that can be incorporated into a sql statement to put this info into the database field.

    What should i do?

  2. #2
    SitePoint Zealot ssttoo's Avatar
    Join Date
    Jan 2004
    Location
    LA, California
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look at http://php.net/filesize and in the comment from
    mehdi at ict dot iut dot ac dot ir
    26-Oct-2003 07:23


    That can probably help you out. Only that if you have a big number of files and a deeply nested directory tree, this can be really slow. (the first time, after that the results are cashed) A cron job that will run and insert those values in a DB might be a solution.

    Regarding your second question, if you want to simply display a file contents in a page - do
    PHP Code:
    include "filename"
    and you're all set.

  3. #3
    SitePoint Zealot ssttoo's Avatar
    Join Date
    Jan 2004
    Location
    LA, California
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing about the php.net post that I referred you to. The function should start with

    PHP Code:
    function fsize($file){
           static 
    $size
    and not just
    PHP Code:
    function fsize($file){
           
    $size

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    system("ls -s") will probably do the job.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •