PHP空间远程下载后的配套删除代码

上篇《PHP空间远程下载代码》解决了在远程PHP空间下载软件的问题,一般来说下载完并通过http方式把已下载到服务器的文件下载到本地后就要把远程服务器上的文件删除,通常情况是通过ftp连接到服务器上去删除对应的文件,可是有时没有使用FTP的条件怎么办?

我这里写了一个删除已经下载文件的PHP代码,跟上篇的downfile.php放在服务上同一个目录下即可,临时目录还是temp。

实现代码:
<?php
// folder to save downloaded files to. must end with slash
$destination_folder = 'temp/';

if (isset($_POST['submit']))
{
if (isset($_POST["unlink"]))
{
while (list($key, $value) = each($_POST["unlink"]))
{
if (file_exists($destination_folder . $value))
{
unlink($destination_folder . $value);
}
}
}
}
?>
<form method="post">
<?php
$files = scandir($destination_folder);
foreach($files as $file)
{
if ($file != '.' && $file != '..')
{
echo '<input name="unlink[]" type="checkbox" value="' . $file . '">' .  $file . '<br>';
}
}
?>
<input name="submit" type="submit" value="Unlink" />
</form>

另外:上面的代码使用到了提交多个checkbox时的PHP处理方法,可供参考。

相关文件下载:unlinkfile.php.txt (下载后删除.txt后缀)

Tags:

Leave a Reply


提醒: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。请务必注意user必须和评论者名相匹配(大小写一致)。