将url文件链接保存到本地服务器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37352702/article/details/78319907
public function saveUrlFile($name)
{
   $path = './Resource/temp_pdf/';
   if (!is_dir($path)) {
      mkdir($path);
      chmod($path, 0777);
   }

   $url = 'http://d.hiphotos.baidu.com/image/pic/item/50da81cb39dbb6fd493c67e70024ab18962b378f.jpg';

   $ext = '.jpg';
   $filename = $path . $name . $ext;
   ob_start();
   readfile($url);
   $img = ob_get_contents();
   ob_end_clean();
   $fp2 = fopen($filename, "a");
   fwrite($fp2, $img);
   fclose($fp2);
}

猜你喜欢

转载自blog.csdn.net/qq_37352702/article/details/78319907