开发者

Download Files to web server from other site using php

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 |
                                         +----------+
                             开发者_JS百科               |
   +------+                                 |      +========+
   | MyPC |                                 +----->| client |
   +------+                                        +========+

plz help....


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


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜