php fopenリモートファイルの関数をダウンロード
1478 ワード
ここ数日お客様に书いたPHPの列车にインタフェースを発表して、よく远隔の添付ファイルの机能を使って、昨日小さい文のブログのところで1段のコードを见て、自分で持ってきて组み合わせて、自动的にカタログを判断してそしてカタログを创立する机能を加えて、それから完全な注釈を追加して、后でよく使います!
<?php
function get_file($url, $folder = "./") {
set_time_limit (24 * 60 * 60); //
$destination_folder = $folder . '/'; // ,
if (!is_dir($destination_folder)) { //
mkdirs($destination_folder); //
}
$newfname = $destination_folder . basename($url); //
$file = fopen ($url, "rb"); // ,
if ($file) { //
$newf = fopen ($newfname, "wb"); //
if ($newf) //
while (!feof($file)) { //
fwrite($newf, fread($file, 1024 * 8), 1024 * 8); //
}
}
if ($file) {
fclose($file); //
}
if ($newf) {
fclose($newf); //
}
return true;
}
function mkdirs($path , $mode = "0755") {
if (!is_dir($path)) { //
mkdirs(dirname($path), $mode); //
mkdir($path, $mode); //
}
return true;
}
//
echo get_file('http://www.kalvin.cn/index.php');
?>