Results 1 to 5 of 5

Thread: filetime() problems

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Exclamation filetime() problems

    hi, im trying to get the 'last modified' time of a file on my server, im currently using the filetime() function to try accomplish this. however, when i run the script, i get met with this error:
    Code:
    Warning: filemtime() [function.filemtime]: stat failed for http://mydomain.co.cc/path/to/file/filetogetsizeof.zip in /home/shifty/public_html/modules/downloads/downloads.php on line 144
    this is the script i am running to try get the last modified time of the file:
    PHP Code:
    $filelocation ''.uhome().'/modules/downloads/downloads/'.$info['download_file'].'';
    $last_modified time() - filemtime($filelocation); 

    if(
    round($last_modified/(24*3600)) >= 1){ // over a day? 
        
    $last_modified /= (24*3600); 
        if(
    round($last_modified) > 6){ // at least a week? 
            
    $last_modified /= 7
            if(
    round($last_modified) > 3){ // .. months? 
                
    $last_modified /= 4
                if(
    round($last_modified) > 11){ 
                    
    $last_modified /= 12
                    
    $output round($last_modified).' years'
                } 
                else{ 
                    
    $output '~'.round($last_modified).' months'
                } 
            } 
            else{ 
                
    $output round($last_modified).' weeks'
            } 
        } 
        else{ 
            
    $output round($last_modified).' days'
        } 

    else if(
    round($last_modified/3600) >= 1){ // At least one hour ago 
        
    $output round($last_modified/3600).' hours'

    else{ 
        if(
    $last_modified/60 1){ // barely a few secs ago 
            
    $output $last_modified.' seconds'
        } 
        else{ 
            
    $output round($last_modified/60).' minutes'
        } 

    if(
    preg_match('/^1[^0-9]/'$output)){ 
        
    $output substr($output0, -1); 

    section_content(''.$output.' ago'); 
    for every different file, i get the same output: 45 years ago

    if anyone could give me any advice, or notice where im going wrong, i would be most greatful
    Last edited by liamallan; 04-21-2011 at 07:57 AM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I get that error when I try to run filemtime() on a non-existent file. Are you sure your file path is correct?

  3. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Also check that all file paths are absolute (start with '/home/www/mysite/...' rather than 'http://mysite/') as that may also be causing problems.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  4. The Following User Says Thank You to Beverleyh For This Useful Post:

    traq (04-22-2011)

  5. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    true, I didn't notice that. filesystem functions work locally on the server; not via the web. Your uhome() function seems to be returning a protocol and url.

  6. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    no; she means that the file paths need to use a local path, not a web-based protocol and URL.

    this:
    http:// mysite.com/somedirectory/somefile.html
    tries to request a file over the internet: i.e., using the http:// protocol.
    filesystem functions do not use the internet to access files; they access files on the server. $_SERVER['DOCUMENT_ROOT'] should be configured with the server path to your website's home directory, so using the following provides the proper path with most web hosts:
    $_SERVER['DOCUMENT_ROOT'] . '/somedirectory/somefile.html'
    ...which will actually produce something like /users/mysite/public_html/somedirectory/somefile.html

  7. The Following User Says Thank You to traq For This Useful Post:

    liamallan (08-13-2011)

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
  •