SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple array question

    PHP Code:
    while ($file readdir($dir))  { 
        if ((
    $file != ".") && ($file != ".."))  {
            
    $fname "$dir_name/$file";
            
    $ftime filectime($fname); 
            
    $fsize filesize($fname); 
            
    $ftime date("m/d/Y G:i"$ftime); 
            
    $x "|";
            
    $key[] = $ftime $x $file $x $fsize;
        } 

    arsort($key);
    for(
    $t=0$t $countfiles$t++)  { 
        
    $listfile each($key); 
        
    $listfile explode("|"$listfile);
        
    $listfilename $listfile[0]; 
        
    $listfiletime $listfile[1]; 
        
    $listfilesize $listfile[2]; 
        echo
    "<b>$listfilename</b> -  $listfiletime -  $listfilesize<br>";

    This script returns a list of 34 lines saying "Array".

    If I comment out
    PHP Code:
    $listfile explode("|"$listfile); 
    the script prints out each value of $key (not usable).

    I've been back to php.net looking over the array page... I geuss I'm being very dense today, but I still don't understand arrays in the context of this script. Clarification, I know what an array is, I'm just having a little trouble getting this to work.
    - Mike
    http://www.georgiaoffroad.com

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay so I looked over your code, but I think you are making this entirely too hard and a little inefficient. I would use a multi-dimensional array instead of a pipe-delimited string. That way you save yourself the time to split the string up and such. This should work a littl faster.

    PHP Code:
    <?
    $base_dir 
    "uploads/";
    $dir opendir($base_dir);
    while (
    $file readdir($dir))  { 
        if ((
    $file != ".") && ($file != ".."))  {
            
    $files[] = array("fname" => $file
                             
    "ftime" => date("m/d/Y G:i"filectime($base_dir.$file)), 
                             
    "fsize" => filesize($base_dir.$file)
                             );
            }

    arsort($files);
    foreach(
    $files as $key => $file) {
        echo 
    "<b>"$files[$key]['fname'], "</b> -  "$files[$key]['ftime'], " -  "$files[$key]['fsize'], "<br>";
        }

    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was what I thought I should do at first, but after a few days of no success I started trying other methods.

    The good news is that the files are printing to the screen, but I am a little confused by the output...

    Code:
         somefile.jpg - 12/31/1969 19:00 -
    The date is the same on all the files, plus the size somehow isn't printing out.

    I thouhgt that it might be that we were processing the date twice, but I can only see where it is being run through date once.

    Thanks for the help/guidance.
    - Mike
    http://www.georgiaoffroad.com

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was having the same probl;em, its because you need to reference that filectime() and filesize() on real files with a correct path. Thats why I added the $base_dir var in there. But you may want to play with that part of it, as its the only part that is not working properly.

    In your script, you assign $fname the value of $dir_name/$file so now you have a full path and filename to work with. In mine I did not do that and instead assigned a value to $base_dir and tacked that onto the front of each one. So you'll need to either adjust $base_dir to be a real path on your system, or change how that var works.

    But the code works fine, at least on my machine.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed $base_dir = 'uploads/' to

    $base_dir = 'C:/wwwroot/uploads/';

    It had no effect on the script, but I think an absolute path will probably solve your problem, as for me uploads/ is relative path to where the script lives, so thats why it worked for me.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple fix, it works fine now. And I think I have a little better understanding of the process.

    Thanks for the help
    - Mike
    http://www.georgiaoffroad.com


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
  •