PHP用curl可以轻松实现下载远程文件到指定目录:

推荐学习:PHP视频教程

<?phpclass Download{   public static function get($url, $file)   {      return file_put_contents($file, file_get_contents($url));   }      public static function curlGet($url, $file)   {      $ch = curl_init();      curl_setopt($ch, CURLOPT_POST, 0);       curl_setopt($ch,CURLOPT_URL,$url);       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);       $file_content = curl_exec($ch);      curl_close($ch);      $downloaded_file = fopen($file, 'w');      fwrite($downloaded_file, $file_content);      fclose($downloaded_file);   }      public static function openGet($url, $file)   {      $in = fopen($url, "rb");      $out = fopen($file, "wb");      while ($chunk = fread($in,8192))      {         fwrite($out, $chunk, 8192);      }      fclose($in);      fclose($out);   }      /**   *   * 创建目录,支持递归创建目录   * @param String $dirName 要创建的目录   * @param int $mode 目录权限   */   public static function smkdir($dirName , $mode = 0777) {     $dirs = explode('/' , str_replace('\\' , '/' , $dirName));     $dir = '';     foreach ($dirs as $part) {        $dir.=$part . '/';        if ( ! is_dir($dir) && strlen($dir) > 0) {           if ( ! mkdir($dir , $mode)) {              return false;           }           if ( ! chmod($dir , $mode)) {              return false;           }        }     }     return true;   }}

更多相关文章

  1. PHP中的递归是什么?实现方式有哪些?
  2. nginx禁止指定目录运行php
  3. php实现对文件夹目录中的文件进行排序的方法
  4. PHP如何下载远程文件到指定目录
  5. 目录间的瞬间转移术(土遁): dtags
  6. ITIL 4:服务目录管理
  7. 文章目录导航
  8. 3: Zabbix5.0自动发现磁盘目录监控
  9. 递归就这么简单

随机推荐

  1. Androidの自定义Spinner实现
  2. 【Android Studio使用教程4】Android Stu
  3. 修改android升级系统后启动系统,提示andro
  4. Android TextView 设置行间距字间距
  5. Android 入门前言之 --布局
  6. android selector 背景选择器的使用, butt
  7. Android Studio系列(四)Version Control II
  8. 8大你不得不知的Android调试工具
  9. android 去掉顶部状态栏
  10. Android相对布局属性全集