【问题标题】:Download Files to web server from other site using php使用 php 将文件从其他站点下载到 Web 服务器
【发布时间】:2011-05-31 05:36:12
【问题描述】:

是否可以将大于 200 mb 的文件直接下载到我的虚拟主机上,这样我就不必将该文件下载到我的计算机上,然后使用我的 ftp 客户端上传。 因为我没有使用 ssh,所以我不能使用 wget。我在想 php 或 per 或 cgi 可能是.. (对所有想法开放..)

+==============+                                  +--------+
|  Big server  | -----------+                +--->|web host|
+==============+            |   +------+     |    +--------+
                            +-->| MyPC |-----+        |
                                +------+              |     +========+
                                                      +---->| client |
                                                            +========+

+============+
| Big Server | ---+
+============+    |                      +----------+
                  +--------------------->| Web Host |
                                         +----------+
                                            |
   +------+                                 |      +========+
   | MyPC |                                 +----->| client |
   +------+                                        +========+

请帮忙....

【问题讨论】:

  • 您对您的网络服务器有什么样的访问权限?只是一个管理面板,shell 访问?
  • 你的服务器上有什么可用的,你有什么许可?
  • 我没有 shell 访问权限,只有 ftp;

标签: php curl download wget


【解决方案1】:

对于卷曲

$url = "http://path.com/file.zip";
$fh = fopen(basename($url), "wb");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
curl_close($ch);

【讨论】:

  • 这终于奏效了,因为我的主机关闭了端口 80 上的出站流量。代码中没有错误...
【解决方案2】:

在php中最简单的可能是:

<?php
copy('http://server.com/big.file','/local/path/big.file');
?>

但是您应该能够执行 wget。特别是如果您的服务器上停用了外部 fopen,这很可能

使用php就像:

<?php 
chdir('/where/i/want/to/download/the/file/');
system('wget http://server.com/big.file');
?>

<?php
system('wget -O /where/i/want/to/save http://server.com/big.file');
?>

卷曲是另一种方式。你可以执行shell命令或使用curl php。

还要确保您要下载到的文件夹(或文件)是可写的

【讨论】:

  • 那么看起来像是服务器限制。
【解决方案3】:

使用 PHP,您可以通过以下方式下载文件:

<?php
$in = fopen('http://example.com/', 'r');
$out = fopen('local-file', 'w');
while(!feof($in)) {
  $piece = fread($in, 2048);
  fwrite($out, $piece);
}
fclose($in);
fclose($out);
?>

这需要两件事:

  • 本地文件必须可由 Web 服务器写入
  • allow_url_fopen 必须在网络服务器上激活

【讨论】:

  • 稍微修改了页面(akx.x10.mx/akx/down.php)我可以从我的服务器下载文件,但其他服务器给出以下错误“无法打开流:连接在 /*** 中超时编辑:哦刚刚看到 allow_url_fopen 被禁用....... (:(
猜你喜欢
  • 2011-01-15
  • 1970-01-01
  • 2015-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-25
  • 1970-01-01
相关资源
最近更新 更多