dsfliu1129 2013-09-05 14:42
浏览 52
已采纳

我可以从http://www.example.com/example.php下载.php文件吗?

I have created a file download system with php. I created like that

phpfiledownload.php
--------------------

<?php 
$file = 'testing.php'; 
if (file_exists($file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($file));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit; 
} ?>

And I also created testing.php file like the following

testing.php
------------
<?php echo "Hello World"; ?>

When I run phpfiledownload.php form my localhost I got testing.php file.

But when I change testing.php to http://www.anotherdomain.com/example.php in phpfiledownload.php I can't download http://www.anotherdomain.com/example.php.

So, how I can got http://www.anotherdomain.com/example.php via my phpfiledownload.php

  • 写回答

3条回答 默认 最新

  • dongsi1944 2013-09-05 14:52
    关注

    To download http://www.example.com/example.php you can use the code below

    file_put_contents("example.php", fopen("http://www.example.com/example.php", 'r'));
    

    Note: If example.php contains php code it will run on the webserver and return the HTML output to you. So your file be the output of example.php and not the source code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度