dongzhenyin2001
2014-10-27 20:25
浏览 76
已采纳

如何在不重定向到index.php文件的情况下列出目录中的文件?

i am writing a simple script to list all the files of an external sites directory. i am using curl for this. the code i have written is below

$url="http://externalsite.com/directory/";

$ch = curl_init();

curl_setopt($ch, CURLOPT_AUTOREFERER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FTPLISTONLY, TRUE);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);       

$data = curl_exec($ch);
curl_close($ch);

echo $data;

but when i execute the above code it is showing the contents of the index.php file which is in the directory. how to list all the files in the directory without redirecting it to index.php file ?

图片转代码服务由CSDN问答提供 功能建议

我正在编写一个简单的脚本来列出外部站点目录的所有文件。 我正在使用curl。 我写的代码在

  $ url =“http://externalsite.com/directory/”; 
   
 \  n 

$ ch = curl_init();

  curl_setopt($ ch,CURLOPT_AUTOREFERER,FALSE); 
curl_setopt($ ch,CURLOPT_HEADER,0); 
curl_setopt($  ch,CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ ch,CURLOPT_URL,$ url); 
curl_setopt($ ch,CURLOPT_FTPLISTONLY,TRUE); 
 
 ncurl_setopt($ ch,CURLOPT_FOLLOWLOCATION,FALSE);  
 
 $ data = curl_exec($ ch); 
curl_close($ ch); 
 
echo $ data; 
   
 
 

但是当我执行上述操作时 代码它显示了目录中index.php文件的内容。 如何列出目录中的所有文件而不将其重定向到index.php文件?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongmei9020 2014-10-27 20:32
    最佳回答

    The behavior is not controlled by the client, it is up to the server to decide what will be served. For example, depending on the server configuration, the default file that will be served by apache is index.php, index.html, or the contents of the directory if none of the above is present there and the Indexes option is not disabled.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题