CaTaLinU Posted February 10, 2012 Share Posted February 10, 2012 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.. Quote Link to comment https://forums.phpfreaks.com/topic/256811-total-files-in-a-folder-through-ftp_connect/ Share on other sites More sharing options...
Adam Posted February 10, 2012 Share Posted February 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256811-total-files-in-a-folder-through-ftp_connect/#findComment-1316535 Share on other sites More sharing options...
CaTaLinU Posted February 10, 2012 Author Share Posted February 10, 2012 sorry, but in ftp im beginner can you help me with the correct php code please ? Quote Link to comment https://forums.phpfreaks.com/topic/256811-total-files-in-a-folder-through-ftp_connect/#findComment-1316537 Share on other sites More sharing options...
Adam Posted February 10, 2012 Share Posted February 10, 2012 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". Quote Link to comment https://forums.phpfreaks.com/topic/256811-total-files-in-a-folder-through-ftp_connect/#findComment-1316544 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.