无法打开php生成的子目录

无法打开php生成的子目录,php,directory,Php,Directory,我的代码有问题。基本上,我可以在现有文件夹中生成和删除子目录。但是,当它显示时,它会尝试打开文件夹,而不查看其中的文件夹。基本上: 主目录: generate.php testCreate.php testDeleteDir.php 上载文件夹 通过上面的php文件测试php生成的文件夹 当我尝试访问测试时,它不会通过上传来访问它。我怎样才能解决这个问题 PHP代码: test.php: <form action="testCreate.php" method="post"> E

我的代码有问题。基本上,我可以在现有文件夹中生成和删除子目录。但是,当它显示时,它会尝试打开文件夹,而不查看其中的文件夹。基本上:

主目录:

generate.php

testCreate.php

testDeleteDir.php

上载文件夹

通过上面的php文件测试php生成的文件夹 当我尝试访问测试时,它不会通过上传来访问它。我怎样才能解决这个问题

PHP代码: test.php:

<form action="testCreate.php" method="post">
  Enter the name of Folder: <input type="text" name="name">
  <input type="submit" value="generate">
</form>
<?php
  $path = "./uploads";

  $dir = opendir($path) or die ("unable to open directory");

  while ($file = readdir($dir)){
    if($file == "." || $file == ".." || $file == "test.php" || $file == "testCreate.php" || $file == "testDeleteDir.php"){
      continue;
    }

    echo "<a href='$file'>$file</a><a href='testDeleteDir.php?dir=$file'> Delete</p><br />";
  }

  closedir($dir);
?>
testCreate.php:

<?php
  $dir = $_POST['name'];

  mkdir("./uploads/" . $dir, 0777);

  header("location: test.php");
?>
testDeleteDir.php:

<?php   
  $dir = $_GET['dir'];
  rmdir("./uploads/" . $dir);
  header("location: test.php");
?>

非常感谢您的帮助!谢谢大家!

您不需要像这样简单地添加链接的路径吗

echo "<a href='$path$file'>$file</a><a href='testDeleteDir.php?dir=$file'> Delete</p><br />";
现在,它同时读取path和文件目录的值

readdir不包括您正在读取的目录的路径,例如

$fd = opendir('/etc');
echo readdir($fd);
将发出回声,而不是/etc/

由于您只读取文件名,但从子目录读取文件名,因此必须在html HREF中包含该子目录:


谢谢抱歉,路径已经包含了额外的斜杠,所以我编辑了它,否则链接将是/uploads//newfolder:P谢谢!!
echo "<a href='uploads/$file'>$file[...snip...]
               ^^^^^^^^