使用 php 从其他站点下载文件到 Web 服务器

发布于 2024-10-09 07:48:18 字数 1118 浏览 0 评论 0原文

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

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

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

请帮助......

is it possible to download file larger than 200 mb onto my web hosting directly so that i dont have to download that file to my computer and then upload using my ftp client.
and as i am not using ssh i cannot use wget. i was thinking of php or per or cgi may be..
(open to all ideas..)

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

or

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

plz help....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南城追梦 2024-10-16 07:48:18

对于卷曲

$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);

For cURL

$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);
晌融 2024-10-16 07:48:18

在 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');
?>

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

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

in php the easiest is probably:

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

however you should be able to execute wget. especially if external fopen is deactivated on your server which is very likely

using php just like:

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

or

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

curl is another way. you can execute the shell command or use curl php.

also make sure the folder (or file) you want to download to is writeable

山人契 2024-10-16 07:48:18

使用 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 服务器写入
  • allowed_url_fopen 必须在 Web 服务器上激活

With PHP you can download the file with this:

<?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);
?>

This requires two things:

  • The local file must be writable by the web server
  • allow_url_fopen must be activated on the web server
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文