Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sorting file names by date

    Hi everyone,

    I am having a little issue with sorting file names in a drop down box by date. At the moment the files are arranged in a random manor and its not easy trying to find the right file you are looking for.

    We have a website that was designed and coded by a company that no longer exists so they can't help us any longer. The backend of the site is designed to manage products, create/delete and etc etc. Before, when we went to add a new product, it would give us a dropdown box with all the images on the server sorted by date, now since we moved servers, it no longer does this.

    So I was wondering if there is something I need to do or maybe change in the coding?

    This is the code snippet:

    PHP Code:
    $sServerDir GetRootPath() . $Config['ProductHiresFilesPath'];
                                        @
    $oCurrentFolder opendir$sServerDir ) ;
                                        while ( @
    $sFile readdir$oCurrentFolder ) )
                                        {
                                                    if ( 
    $sFile != '.' && $sFile != '..' && !is_dir$sServerDir '/' $sFile ) )
                                                    {
                                                                echo 
    "
                                                                            <option value='$sFile' "
    .(($row->product_hires_file == $sFile)?"selected='selected'":'').">$sFile</option>\n";
                                                    }
                                        } 
    Any help is appreciated!

  • #2
    New Coder
    Join Date
    Sep 2010
    Location
    The Twilight Zone
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Try echoing this statement in your code
    Code:
    $sServerDir = GetRootPath() . $Config['ProductHiresFilesPath']; 
    echo $sServerDir;
    and make sure that the path matches the path that your files are in. If you changed the name of your folders, that may be an issue.

    If it doesn't output the correct url ( or nothing at all), get rid of GetRootPath() and try this:

    Code:
    $sServerDir = $_SERVER['HTTP_HOST'] . $Config['ProductHiresFilesPath']; 
    echo $sServerDir;
    There may also be issues with the $Config (Array of file paths?). But try those steps and let me know what you run into.

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for reply,

    Unfortunately that did nothing. The drop-down box still sorts the items randomly and I we need them by date of upload which would make the zip file easier to find.

    See the attached image please. Would you like the code for the whole file?
    Attached Thumbnails Attached Thumbnails Sorting file names by date-hirest_image_selection.jpg  

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,560
    Thanks
    76
    Thanked 105 Times in 104 Posts
    Take the part you need out of it, here is a complete one.

    PHP Code:
    <?php

    /* Rendering */ 
    function list_dir($path

    $items get_sorted_entries($path); 

    if (!
    $items
    return; 


    foreach(
    $items as $item

    if (
    $item->type=='dir'

        echo (
    "<li><img alt='PDF' src='../../../images/Folder.png'>".$item->entry."
    \n"
    );
        echo 
    "<ul>\n";
    list_dir($item->full_path); 

    else 

    echo 
    "<img alt='PDF' src='../../../images/PDF.png'> ".$item->entry."<br/>";



    echo 
    "</ul>"
    echo 
    "</li>\n";



    /* Finding */ 
    function get_sorted_entries($path

    $dir_handle = @opendir($path) ; 
    $items = array(); 

    while (
    false !== ($item readdir($dir_handle))) 

    $dir =$path.'/'.$item
    if ( 
    $item == '.' || $item =='..' 
    continue; 

    if(
    is_dir($dir)) 

    $items[] = (object) array('type'=>'dir','entry'=>$item'full_path'=>$dir); 

    else 

    $items[] = (object) array('type'=>'file','entry'=>$item'full_path'=>$dir); 


    closedir($dir_handle); 

    usort($items,'_sort_entries'); 

    return 
    $items


    /* Sorting */ 
    function _sort_entries($a$B

    return 
    strcmp($a->entry,$b->entry); 
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

            <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
            <title>TITLE</title>
            
            <link rel="stylesheet" href="../jquery.treeview.css" />
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

            <script src="../lib/jquery.cookie.js" type="text/javascript"></script>
            <script src="../jquery.treeview.js" type="text/javascript"></script>
            
            <script type="text/javascript" src="demo.js"></script>
            
            </head>
            <body>
            
            <div id="treecontrol">
                    <a title="Collapse the entire tree below" href="#"> Collapse All</a> | 
                    <a title="Expand the entire tree below" href="#"> Expand All</a> | 
                    <a title="Toggle the tree below, opening closed branches, closing open branches" href="#">
                    Toggle All</a>
            </div>

    <ul id="red" class="treeview-red">
    <?php 
    list_dir
    ("directory you want to search"); 
    ?>
            </ul>


    <hr />

     
    </body></html>
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not sure which bit as I am not fluent in php!


  •  

    Posting Permissions

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