Welcome Guest, Not a member yet? Register   Sign In
FTP Class - How can I browse ?
#1

[eluser]Saymont[/eluser]
Hello,

Im trying to use FTP Class just to browsing my images files.
So I use:

Code:
$this->ftp->list_files($dir);

Where $dir is my FTP directory that I want to browse.

Problem 01:

I dont now how to swap this variable ($dir) while browsing.
Example:
Suppose that $dir = www

Results:
_____________
.
..
docs
images
tree.jpg
______________

What kind of uri/link I insert into this values to increment www/.

If I use $dir = uri_string, the beginning of sentence gonna be wrong because have another "words" there.

How can I do it ?


Problem 02:

How can I list Folders first ?


Thank you ALL
#2

[eluser]Senthilguru[/eluser]
Hi dude,

To get the files list from ftp u have to pass the path of your image folder.


lets consider ur directory structure like this...

public_html->test->images folder

then u have to pass the path like this

Code:
$dir = $_SERVER['DOCUMENT_ROOT'].'/test/images/';
$list = $this->ftp->list_files($dir);

print_r($list);


Have a nice day.


cheers,
senthilguru.e
cogzideltemplates.com
#3

[eluser]Saymont[/eluser]
hello,

thank you for reply.
List path is not the problem. The problem is after list....
After list the folder i want to still browser another folders. So I cant use static address like you said "/test/images/". It must be a variable because it must change every time I change the folder by clicking at the folder name.

thank you
#4

[eluser]Phil Sturgeon[/eluser]
If I am understanding this you want to be able to pass the directory as a URL parameter to browse any folder you like. Try the following:

Code:
<?php

class Browse extends Controller {

  function directory() {

    $dir = $_SERVER['DOCUMENT_ROOT'];
    $dir .= func_num_args() > 0 ? implode('/', func_get_args()) : 'whatever_default_folder';
    
    $list = $this->ftp->list_files($dir);

    print_r($list);

  }

}

?>

That means you can pass it the following URL http://example.com/browse/directory/test/images/.
#5

[eluser]Saymont[/eluser]
Thank you for reply Pyromaniac.
Your code was very useful to understand the main idea but I have an error:

func_get_args(): Can't be used as a function parameter in .....

the line is:

Code:
$dir = func_num_args() > 0 ? implode('/', func_get_args()): "/" ;

All my function is:

Code:
function ftp()
    {
      
        // carrega modelo
        $this->load->model('Centralmidia_ftp_model');
        $this->load->library('ftp');
    
        $carrega_ftp = $this->Centralmidia_ftp_model->carrega_ftp();
        
        foreach($carrega_ftp as $row)
        {

            $config['hostname'] = $row->ftp_servidor;
            $config['username'] = $row->ftp_usuario;
            $config['password'] = $row->ftp_senha;
            $config['debug'] = TRUE;
            $config['port']     = 21;
            $config['passive']  = FALSE;
            $config['debug']    = TRUE;
            
            $ftp_url = $row->ftp_url;
            
        }

        $this->ftp->connect($config);
        
        //$diretorio = $this->Centralmidia_ftp_model->diretorio_ftp();    
        $dir = func_num_args() > 0 ? implode('/', func_get_args()): "/" ;

        $list = $this->ftp->list_files($dir);

        $data['ftp_url'] = $ftp_url;
        $data['list'] = $list;
        $this->load->view('admin/ftp/listagem_view',$this->_comum($data));
            
        
    }
#6

[eluser]Saymont[/eluser]
Lets see problem 2 now:

How list FOLDERS first ????????


Problem 1 its ok:::::

Code:
function ftp()
    {
      
        // carrega modelo
        $this->load->model('Centralmidia_ftp_model');
        $this->load->library('ftp');
    
        $carrega_ftp = $this->Centralmidia_ftp_model->carrega_ftp();
        
        foreach($carrega_ftp as $row)
        {

            $config['hostname'] = $row->ftp_servidor;
            $config['username'] = $row->ftp_usuario;
            $config['password'] = $row->ftp_senha;
            $config['debug'] = TRUE;
            $config['port']     = 21;
            $config['passive']  = FALSE;
            $config['debug']    = TRUE;
            
            $ftp_url = $row->ftp_url;
            
        }

        $this->ftp->connect($config);
        
        //$diretorio_ftp = func_num_args() > 0 ? implode('/', func_get_args()): "/" ;
    
        $dirs = func_get_args();
        $diretorio_ftp = implode("/", $dirs);
        
        echo $diretorio_ftp;
        
        $list = $this->ftp->list_files($diretorio_ftp);

        $data['ftp_url'] = $ftp_url;
        $data['list'] = $list;
        $this->load->view('admin/ftp/listagem_view',$this->_comum($data));
            
        
    }




Theme © iAndrew 2016 - Forum software by © MyBB