本文介绍了PHP + FTP删除文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚编写了一个PHP脚本,该脚本应该连接到FTP并删除特殊文件夹中的所有文件。
I just wrote a PHP Script which should connect to FTP and delete all files in a special folder.
看起来像这样,但是我不知道该使用什么命令我需要删除文件夹日志中的所有文件。
It looks like this, but I have no clue what command I need to delete all files in the folder logs.
有什么想法吗?
<?php
// set up the settings
$ftp_server = 'something.net';
$ftpuser = 'username';
$ftppass = 'pass';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppass);
// delete all files in the folder logs
????????
// close the connection
ftp_close($conn_id);
?>
推荐答案
// Delete all files in the folder logs
$logs_dir = "";
ftp_chdir($conn_id, $logs_dir);
$files = ftp_nlist($conn_id, ".");
foreach ($files as $file)
{
ftp_delete($conn_id, $file);
}
您可能想对目录进行一些检查,但是从基本的角度来说,就是这样。
You might want to do some checking for directories, but at a basic level, that is it.
这篇关于PHP + FTP删除文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!