IT猫扑网:您身边最放心的安全下载站! 最新更新| 软件分类| 专题汇总| 手机版

您当前所在位置:IT猫扑网 > 网络编程 > PHP编程 > PHP采集图片实例(PHP采集)

PHP采集图片实例(PHP采集)

时间:2015-06-28 00:00 来源:IT猫扑网|http://www.itmop.com/ 作者:网管联盟 我要评论(0)

<?php
/**
*  采集图片php程序
*
*  Copyright(c) 2008 by 小超(ccxxcc) All rights reserved
*
*  To contact the author write to {@link mailto:ucitmc@163.com}
*
* @author ccxxcc
* @version $Id: {filename},v 1.0 {time} $
* @package system
*/

set_time_limit(0);
/**
* 写文件
* @param    string  $file   文件路径
* @param    string  $str    写入内容
* @param    char    $mode   写入模式
*/
function wfile($file,$str,$mode='w')
{
    $oldmask = @umask(0);
    $fp = @fopen($file,$mode);
    @flock($fp, 3);
    if(!$fp)
    {
        Return false;
    }
    else
    {
        @fwrite($fp,$str);
        @fclose($fp);
        @umask($oldmask);
        Return true;
    }
}

function savetofile($path_get,$path_save)
{
        @$hdl_read = fopen($path_get,'rb');
        if($hdl_read == false)
        {
                echo(&<span style='color:red'>$path_get can not get</span>&);
                Return ;
        }
        if($hdl_read)
        {
                @$hdl_write = fopen($path_save,'wb');
                if($hdl_write)
                {
                        while(!feof($hdl_read))
                        {
                                fwrite($hdl_write,fread($hdl_read,8192));
                        }
                        fclose($hdl_write);
                        fclose($hdl_read);
                        return 1;
                }
                else
                        return 0;
        }
        else
                return -1;
}

function getExt($path)
{
        $path = pathinfo($path);
        return strtolower($path['extension']);
}

/**
* 按指定路径生成目录
*
* @param    string     $path    路径
*/
function mkDirs($path)
{
    $adir = explode('/',$path);
    $dirlist = '';
    $rootdir = array_shift($adir);
    if(($rootdir!='.'||$rootdir!='..')&&!file_exists($rootdir))
    {
        @mkdir($rootdir);
    }
    foreach($adir as $key=>$val)
    {
        if($val!='.'&&$val!='..')
        {
            $dirlist .= &/&.$val;
            $dirpath = $rootdir.$dirlist;
            if(!file_exists($dirpath))
            {
                @mkdir($dirpath);
                @chmod($dirpath,0777);
            }
        }
    }
}

/**
* 从文本中取得一维数组
*
* @param    string     $file_path    文本路径
*/
function getFileListData($file_path)
{
    $arr = @file($file_path);
    $data = array();
    if(is_array($arr) && !empty($arr))
    {
        foreach($arr as $val)
        {
            $item = trim($val);
            if(!empty($item))
            {
                $data[] = $item;
            }
        }
    }
    Return $data;
}

//采集开始

//传入自己的需要采集的图片url列表文本文件 每个图片url写一行
$url_file = isset($_GET['file'])&&!empty($_GET['file'])?$_GET['file']:null;
$txt_url = &txt/&.$url_file;

$urls = array_unique(getFileListData($txt_url));
if(empty($urls))
{
        echo('<div style=&color:red&>无链接地址</div>');
        die();
}
$save_url = &images/&.date(&y_m_d&,time()).&/&;
mkDirs($save_url);  //按日期建立文件夹
$i = 1;
if(is_array($urls)&&count($urls))
{
        foreach($urls as $val)
        {
                savetofile($val,$save_url.date(&His&,time()).&_&.$i.&.&.getExt($val));
                echo($i.&.&.getExt($val).& gotn&);
                $i++;
        }
}

echo('<div style=&color:green&>finish</div>');

?>


关键词标签:采集,实例,图片,ifp,v

相关阅读 2021年最好用的10款php开发工具推荐 plsql developer怎么连接数据库-plsql developer连接数据库方法 php利用淘宝IP库获取用户ip地理位置 在 PHP 中使用命令行工具 php出现Cannot modify header information问题的解决方法大全 详解ucenter原理及第三方应用程序整合思路、方法

文章评论
发表评论

热门文章 2021年最好用的10款php开发工具推荐 2021年最好用的10款php开发工具推荐 plsql developer怎么连接数据库-plsql developer连接数据库方法 plsql developer怎么连接数据库-plsql developer连接数据库方法 在 PHP 中使用命令行工具 在 PHP 中使用命令行工具 php应用程序安全防范技术研究 php应用程序安全防范技术研究 关于php curl获取301或302转向的网址问题 关于php curl获取301或302转向的网址问题

相关下载

人气排行 详解ucenter原理及第三方应用程序整合思路、方法 plsql developer怎么连接数据库-plsql developer连接数据库方法 PHP中防止SQL注入攻击 PHP会话Session的具体使用方法解析 PHP运行出现Notice : Use of undefined constant 的解决办法 PHP如何清空mySQL数据库 CakePHP程序员必须知道的21条技巧 PHP采集图片实例(PHP采集) 完美解决failed to open stream: HTTP request failed! <? phpinfo() ?>无法执行的解决办法 2021年最好用的10款php开发工具推荐 用header或meta实现PHP页面编码的区别