代码之家  ›  专栏  ›  技术社区  ›  I am the Most Stupid Person

从站点目录的url下载文件

  •  -6
  • I am the Most Stupid Person  · 技术社区  · 7 年前

    https://example.com/directory . (由于index.php文件在此目录中可用,我们不知道这些文件的文件名)。

    是否有任何可能的方法使用PHP或Linux命令查找上述四个文件的名称?

    6 回复  |  直到 5 年前
        1
  •  8
  •   Maksym Fedorov    7 年前

    您必须记住:如果您的web服务器不允许扫描目录,则无法获取文件名。但如果该目录在web服务器中共享,则可以使用 wget 指挥部。例如:

    wget -nv -r -np '*.*' https://example.com/directory/
    
        2
  •  0
  •   Parvej Alam    7 年前
    <?php
    $files=[];    
    $folder="/directory/directory/directory/";
    if (is_dir($folder)){                       // check whether exists or not
        $allfiles = glob($folder.'/*.*');       // Read all filenames of $folder directory
        foreach($allfiles as $imgFile) {
            $files[]=$imgFile;              // Putting the names of $folder directory to array one by one
        }
    }
    echo "<pre>";
    print_r($files);                          // printing the file name array to list aal names
    echo "</pre>";
    
        3
  •  0
  •   Vineet1982    7 年前

    我认为您根本不了解HTTP协议。根据HTTP协议,它不知道任何目录/子目录。您不能在HTTP协议中这样做。

    http://example.com/directory

        4
  •  0
  •   user3762527    7 年前
    <?php 
    $dir = 'directory';
    $filesArr = scandir($dir);
    
    $files = array();
    for($i=2; $i<count($filesArr);++$i){
    if($filesArr[$i]=="index.php"){ continue; }
    $files[] = $filesArr[$i];
    
    
    }
    
    $zipname = 'file1.zip';
    $zip = new ZipArchive;
    $zip->open($zipname, ZipArchive::CREATE);
    foreach ($files as $file) {
      $zip->addFile($file);
      $zip->addFile($dir.'/'.$file,   $dir.'/'.$file);
    }
    
    
    header('Content-Type: application/zip');
    header('Content-disposition: attachment; filename='.$zipname);
    header('Content-Length: ' . filesize($zipname));
    readfile($zipname);
    $zip->close();
    exit;
    ?>
    
        5
  •  0
  •   Kamran Sohail    7 年前

    试试这个,我在我的项目中使用下面的示例,它对我来说很好,

    <?php
    $directory='directory';
    $handler= opendir("$directory"."/");
    $i=0;
    while (false !== ($file = readdir($handler))) {
        if ($file != '.' && $file !='..'){
                echo $file.'<br>';
        }
    }
    
    ?>
    
        6
  •  0
  •   Roko C. Buljan    5 年前

    example.com 类似以下目录的目录: /multimedia/ mp3,jpg,png 等等,但是 也没有 tmp index.html•C=D;O=D :

    wget -r -R "*.html*" -np -nd -l 1 example.com/multimedia/
    

    哪里:

    -r             # Recursive
    -R "*.html*"   # Reject tmp and listing html files
    -np            # Don't ascend to the parent directory
    -nd            # Don't create parent directories
    -l 1           # Only one level deep (multimedia/ folder only)
    

    要了解更多信息,请运行 man wget wget --help gnu.org WGET

        7
  •  -4
  •   Jnt0r    7 年前

    您可以使用PHPs scandir 试试这个:

    <?php
        $files = scandir('./');
        print_r($files);
    

    这将打印当前目录中的所有文件。更多信息 here

    推荐文章