Jump to content

Total Files in a Folder through ftp_connect


CaTaLinU

Recommended Posts

Deci eu am asa

config.php

 

code:

<?php

error_reporting(0);

 

 

$host = "93.xx.xx.xx";

$user = '[email protected]';

$password = 'password';

$path = '/direcotry';

?>

 

 

 

apoi

 

code:

<?php include ('config.php');

                $ftp_connection = @ftp_connect($host);

                        @ftp_login($ftp_connection, $user, $password);

                        $parent = substr($path, 0, strrpos($path, "/"));

                          if (glob($path . "*.ini") != false)

                          {

                              $filecount = count(glob($path . "*.ini"));

                              echo $filecount;

                          }

                          else

                          {   

                              echo 0;

                          }

                        ftp_close($ftp_connection); ?>     

 

 

it should count the files with the extension .ini

 

But always on the page shows 0

 

Please Help..

glob is only executed on your local file system, not the remote. You need to use the special ftp_* functions. To get a list of files in a directory you can use ftp_nlist, and with the returned array loop through and match against a regular expression.

FTP is made simple in PHP. You already have your connection to the server, just pass in the variable holding the connection ($ftp_connection) and the directory you wish to search in ($path) to the ftp_nlist function. The return will be an array of files in that directory. From that point on it's standard PHP; just use preg_match to find the files which end in ".ini".

 

Edit: in-fact you can just use strrpos() to check the end of the string is ".ini".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.