Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to print all the files in a directory using PHP

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 520
    Comment on it

    Hello Reader's if you need to get all the files that exists inside any directory then you can get it by using codeigntier FTP class library. This is quick and very easy to get result.
    For example if you have amazon S3 bucket and you wish to get all the results from the bucket then also you can load this liberay.

    Start with your controller put this liberary code in it.

    $this->load->library('ftp');
    $config['hostname'] = 'your.ftp.address.com';
    $config['username'] = 'ftp.username';
    $config['password'] = 'ftp.password';
    $config['debug']    = TRUE;
    $this->ftp->connect($config);
    $MyFiles= $this->ftp->list_files('/DirectoryAddress/');
    print_r($MyFiles);
    $this->ftp->close();
    

    This is most easy alternate method that the frameworks are now giving to user and it save the time.

    Also if you want to put your folder as it is to server, then you just to write the code as below:-

    $this->ftp->mirror('/path/to/myfolder/', '/public_html/MyDirectoy/');
    

    Here the 'mirror' liberary will copy the source folder to destination folder as it is.

    Now see how to upload a single file to Directory.

    $this->ftp->upload('/local/path/Project/upload.html', '/public_html/upload.html', 'ascii', 0777); 
    

    Here 'upload' library will copy upload.html from local pc to server directory. Here you can see how to set the permission also and that can be passed as an octal value in the fourth parameter. So by using these single lines of code you can make your code easy to maintain

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: