donpvtzuux37724 2014-10-02 16:23
浏览 32

删除名为“.html”的文件

I accidentally created a file with no name http://website.com/myFolder/.html,

now, in the control panel of my webhost, this file is not listed, I cannot see or delete it...

but I can see it using this "myList.php" file: (http://website.com/myFolder/myList.php):

<?php
echo "<ol>";
if ($handle = opendir('.')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            echo '<li><a href="'.$entry.'" target="_blank">'.$entry.'</a></li>';
        }
    }
    closedir($handle);
}
echo "</ol>";
?>

This "myList.php" file outputs all the files present in the directory: http://website.com/folder/
also the file with no name http://website.com/myFolder/.html

How can I delete this file?

I tried to create another .php file called http://website.com/myFolder/myDelete.php,
and use the php function unlink():

<?php

$path = "../myFolder/.html";
if(file_exists($path)){
    if (is_file($path)){
        //unlink($path);
        if (!unlink($file)){
            echo ("Error deleting".$path);
        }else{
            echo ("Deleted".$path);
        }
    }
}

?>

But it doesn't work.

  • 写回答

3条回答 默认 最新

  • dongshi2588 2014-10-02 16:26
    关注

    Files and directories that begin with . are considered "hidden" on *nix systems. You can see them with ls -la but not with just ls.

    Try changing the $file variable to just be the name of the file ".html". Make sure to use the $file variable for the delete - this is not defined in your example.

    $file = ".html";
    
    if ( file_exists( $file ) ){
        if ( ! unlink( $file ) ){
            echo "Error deleting '$file'" );
        } else{
            echo "Deleted '$file'";
        }
    } else {
        echo "File '$file' does not exist!";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大