Results 1 to 2 of 2

Thread: Getting file directories

  1. #1
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default Getting file directories

    So I am using AJAX with PHP to get the folders inside the current directory I am in. Well at least, im attempting to.
    JQuery:
    Code:
    $(function(){
    	getFolders('#folders');
    })
    function getFolders(id){
    	var path = window.location.pathname;
    	
    	$.ajax({
    		type: "POST",
    		url: "get.php", //Your required php page
    		data: {type: "folders", dir: path}, //pass your required data here
    		success: function(response){
    			$(id).append(response);
    		}
    	});
    }
    PHP page (get.php):
    PHP Code:
    $hiddenFolders = array('copyfiles','css','images','js');
    $dir trim($_POST['dir']);
    $type $_POST['type'];

    if(
    $type == "folders")
        
    $new_array array_diff(ffnames($dir$type), $hiddenFolders);

    echo 
    '<tr><td>Check: '.count($new_array).'</td></tr>';


    function 
    ffnames($dir$type){
        
    $everything = array();
        if (
    $handle opendir($dir)) {
            while ((
    $file readdir($handle)) !== false){
                if (!
    in_array($file, array('.''..'))){
                    if(
    $type == "folders" && is_dir($dir.$file)){
                        
    array_push($everything,$file);
                    }else if(
    $type == "files" && !is_dir($dir.$file)){
                        
    array_push($everything,$file);
                    }
                }
            }
        }
        
        return 
    $everything;

    However it says that 'dir' doesnt exist (doing this from a localhost but will also be on server)
    Last edited by Deadweight; 10-01-2014 at 10:44 PM.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  2. #2
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Actually i figured it out:
    PHP Code:
    $hiddenFolders = array('copyfiles','css','images','js');
    $dir './';
    $type $_POST['type'];

    if(
    $type == "folders"){
        
    $new_array = array();
        
    $new_array array_diff(ffnames($dir$type), $hiddenFolders);
    }
    //count(scandir($dir));
    //$new_array = array();
    //$new_array = ffnames($dir, $type);
    $table '<tr>';
    foreach(
    $new_array as $value){
        
    $table .= '<td>'.$value.'</td>';
    }
    $table .= '</tr>';
    echo 
    $table;

    function 
    ffnames($dir$type){
        
    $everything = array();
        if (
    $handle opendir($dir)) {
            while ((
    $file readdir($handle)) !== false){
                if (!
    in_array($file, array('.''..'))){//All Objects
                    
    if($type == "folders" && is_dir($dir.$file)){
                        
    array_push($everything,$file);
                    }else if(
    $type == "files" && !is_dir($dir.$file)){
                        
    array_push($everything,$file);
                    }
                }
            }
        }
        
        return 
    $everything;

    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

Similar Threads

  1. Uploading a file to 2 directories
    By arsenalbates in forum PHP
    Replies: 1
    Last Post: 02-22-2011, 09:17 PM
  2. Directories unwriteable. php.ini help.
    By chetanmadaan in forum PHP
    Replies: 1
    Last Post: 01-17-2009, 09:06 AM
  3. Variables in directories
    By AndyA in forum PHP
    Replies: 5
    Last Post: 11-27-2008, 07:20 PM
  4. Sub Directories
    By mstolton in forum JavaScript
    Replies: 3
    Last Post: 07-12-2008, 03:57 PM
  5. .htaccess and sub directories
    By simonf in forum Other
    Replies: 4
    Last Post: 07-18-2007, 02:54 PM

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
  •