欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺談php fopen下載遠(yuǎn)程文件的函數(shù)

 更新時間:2016年11月18日 09:32:58   投稿:jingxian  
下面小編就為大家?guī)硪黄獪\談php fopen下載遠(yuǎn)程文件的函數(shù)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

如下所示:

//下載附件
function get_file($url, $folder = "./") {  
  set_time_limit (24 * 60 * 60); // 設(shè)置超時時間  
  $destination_folder = $folder . '/'; // 文件下載保存目錄,默認(rèn)為當(dāng)前文件目錄  
  if (!is_dir($destination_folder)) { // 判斷目錄是否存在  
      mkdirs($destination_folder); // 如果沒有就建立目錄  
  }  
  $newfname = $destination_folder . basename($url); // 取得文件的名稱  
  $file = fopen ($url, "rb"); // 遠(yuǎn)程下載文件,二進(jìn)制模式  
  if ($file) { // 如果下載成功  
      $newf = fopen ($newfname, "wb"); // 遠(yuǎn)在文件文件  
    if ($newf) // 如果文件保存成功  
      while (!feof($file)) { // 判斷附件寫入是否完整  
        fwrite($newf, fread($file, 1024 * 8), 1024 * 8); // 沒有寫完就繼續(xù)  
    }  
  }  
  if ($file) {  
    fclose($file); // 關(guān)閉遠(yuǎn)程文件  
  }  
  if ($newf) {  
    fclose($newf); // 關(guān)閉本地文件  
  }  
  return true;  
}  
function mkdirs($path , $mode = "0755") {  
  if (!is_dir($path)) { // 判斷目錄是否存在  
      mkdirs(dirname($path), $mode); // 循環(huán)建立目錄   
    mkdir($path, $mode); // 建立目錄  
  }  
  return true;  

}




// 使用示例  
echo get_file('xxxxx.pdf');  

以上這篇淺談php fopen下載遠(yuǎn)程文件的函數(shù)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論