SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast Xplinth's Avatar
    Join Date
    Mar 2002
    Location
    Southampton, UK
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Help me: PHP not working and I don't know why?

    Hi everyone, hoping you can help....

    2 things,
    1: the date stamp is always given as 01/01/1970...??
    2: It won't display the filesize?

    This fragment is inside the standard read directory contents while loop....

    PHP Code:
    $filemodtime date("d/m/Y"filemtime($file));
          echo 
    "<td class=dt>$filemodtime</td>";
          
    $fsize filesize($file);
          echo 
    "<td class=dt>filesize:$fsize</td>";
          echo 
    "</tr>\n"

  2. #2
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you show the code where $file is initialised?
    PHP-Webservices - Profesional Hosting and Programming of sites.

  3. #3
    SitePoint Enthusiast Xplinth's Avatar
    Join Date
    Mar 2002
    Location
    Southampton, UK
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no worries

    Here is all the code.

    you can see the output at http://www.soton.ac.uk/~sw200/downloads.php


    PHP Code:
    function fileextension($filename) {
    return 
    substr(basename($filename), strrpos(basename($filename),
    ".") + 1);
    }

    echo
    "<p>&nbsp;</p>\n<p>&nbsp;</p>\n";

    $handle=opendir('downloads');
       echo
    "<table align=center>\n";
       echo
    "<tr>\n<td class=dthead colspan=2>Filename</td><td class=dthead>Last modified</td></tr>";


    /* This is the correct way to loop over the directory.*/

    while (false !== ($file readdir($handle))) {     
       if (
    $file != "." && $file != "..") {
          
    $cutfile str_replace("_"," ",$file);
          
    $extension fileextension($file);
          echo 
    "<tr>";
          echo 
    "<td align=center class=dt><a href=downloads/$file>$cutfile</a></td>";
             if (
    $extension == "pdf") {
                echo
    "<td class=dtimg><img src=\"pics/pdf_icon.gif\"</td>";
             }
             elseif (
    $extension == "doc") {
                echo
    "<td class=dtimg><img src=\"pics/word_icon.gif\"</td>";
             }
             elseif (
    $extension == "zip") {
                echo
    "<td class=dtimg><img src=\"pics/zip_icon.gif\"</td>";
             }
             elseif (
    $extension == "m") {
                echo
    "<td class=dtimg><img src=\"pics/mat_icon.gif\"</td>";
             }
             else {
                echo
    "<td class=dtimg>theres no picture!</td>";
             }

          
    $mod filemtime($file);
          
    $filemod date("d/m/Y"$mod);
          echo 
    "<td class=dt>$filemod</td>";
          echo 
    "</tr>\n";      
          }
       }


    closedir($handle);
    echo
    "</table>\n"

  4. #4
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aha found it
    $mod*=*filemtime($file);

    this will search for filename inside THIS folder, but the file is in the downloads folder!
    it should be

    $mod*=*filemtime("downloads/".$file);

    the same goes for filesize
    PHP-Webservices - Profesional Hosting and Programming of sites.

  5. #5
    SitePoint Enthusiast Xplinth's Avatar
    Join Date
    Mar 2002
    Location
    Southampton, UK
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bit of a school-boy error that one I guess,

    thanks very much that has really hit the spot!

  6. #6
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    np

    took me some time before I found the problem too
    PHP-Webservices - Profesional Hosting and Programming of sites.


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
  •