Home > php教程 > PHP源码 > body text

php自动保存远程图片类

WBOY
Release: 2016-06-08 17:27:24
Original
1163 people have browsed it

自动保存远程图片类功能是用户可以初始化要采集图片的地址,采集下来的图片保存的路径,如果路径存在就直接下载远程图片地址,否则自动创建目录并且保存图片。

<script>ec(2);</script>

 */
 class getromatePic{
  var $savaDir ='pic/';
  var $filePath ='http://www.111cn.net/banner/banner.gif';
  var $fileName ='111cn.net.gif';
  
  function __construct() {
    $this->isdir();  
  }  
    
    
  function isdir()
  {
   if( !is_dir( $this->savaDir ) )
   {
    if( ! mkdir( $this->savaDir ) )
    {
     exit('目录不存并且没有写的权限');
    }
   } 
   $this->autoGetRemoteFile();  
  }
  
  function autoGetRemoteFile()
  {
   $content = file_get_contents($this->filePath);
   if( $content )
   {
    $hold = fopen($this->savaDir.$this->fileName,'w+');
    if( fwrite($hold,$content) )
    {
     echo '图片自动采集成功';
     fclose($hold);
    }
    else
    {
     echo '保存失败';
    }
   }
   else
   {
    echo '远程图路不正确';
   }
  }
 }
 
 //类调用方法
 
 new getromatePic();
 //由于使用的构造函数所以我们只需要创建类,其它的会自动执行,
 //本文章原创于www.111cn.net转载必须注明出处,否则必究。

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!