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 = 'X@google.xxx';

$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..

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.