php自动保存远程图片类
自动保存远程图片类功能是用户可以初始化要采集图片的地址,采集下来的图片保存的路径,如果路径存在就直接下载远程图片地址,否则自动创建目录并且保存图片。
<?php class getromatePic { var $savaDir = 'pic/'; var $filePath = 'http://www.phprm.com/banner/banner.gif'; var $fileName = 'phprm.com.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(); //由于使用的构造函数所以我们只需要创建类,其它的会自动执行,
教程链接:http://www.phprm.com/code/c0616f97f5e219b26525375ec9389c9e.html
随意转载~但请保留教程地址★