php 通过网络地址文件 下载到服务器或者本地

2023-03-23  本文已影响0人  风度翩翩的程序猿
$url = $input['url']; // 网络地址
 $local_file = './upload/excel/'.date('Y_m_d_H').'.xlsx';// 本地路径 不存在可以自动创建
  // 打开远程文件
  $remote_file = fopen($url, 'r');
   // 打开本地文件
 $fp = fopen($local_file, 'w');
 // 使用流下载文件内容
 while (!feof($remote_file)) {
           fwrite($fp, fread($remote_file, 1024));
    }
      // 关闭文件
     fclose($remote_file);
上一篇 下一篇

猜你喜欢

热点阅读