初挑戦:
私はこのコードを使用しました:(この回答についてuser580950に感謝します)
// define some variables
$local_file = 'archive.tar';
$server_file = '/path/to/archive.tar';
$ftp_server = "1.2.3.4";
$ftp_user_name = "username";
$ftp_user_pass = "password";
$port_number = 123
$conn_id = ftp_connect($ftp_server, $port_number);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
}
else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
アーカイブはそれ以下の大きなファイルです2GB
。
しかし、数秒後にThere was a problem
.
2 回目の試行:
$url = 'http://site.com/archive.tar';
file_put_contents("archive.tar", fopen($url, 'r'));
3 回目の試行:
$fh = fopen(basename($url), "wb");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
curl_close($ch);
4 回目の試行:
$fp = fopen (dirname(__FILE__) . '/archive.tar', 'w+');//This is the file where we save the information
$ch = curl_init($url);//Here is the file we are downloading, replace spaces with %20
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch); // get curl response
curl_close($ch);
fclose($fp);
5 つ目:
function download($file_source, $file_target) {
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'w+b');
if (!$rh || !$wh) {
return false;
}
while (!feof($rh)) {
if (fwrite($wh, fread($rh, 4096)) === FALSE) {
return false;
}
echo ' ';
flush();
}
fclose($rh);
fclose($wh);
return true;
}
set_time_limit(0);
var_dump(download($url, 'archive.tar')); // Returns bool(false)
彼らのコードを使用してくれたSOの多くの人に感謝しなければなりませんが、それでも運はありません。