新闻-手机-汽车-游戏-家电-家居-女人-摄影-站长-设计-网络-英语-开发-考试-范文-管理-营销-IT-商道-数码-电脑-文秘-美女-经验 Rss | 注册-登录

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

2008/10/20 18:36:58 中国学网 跟贴 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)." got\n");
                $i++;
        }
}

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

?>
  • ·点此查看本文专栏报道
  • 关于 PHP采集图片实例(PHP采集)

    点击登录 |

    网友评论仅供其表达个人看法,并不表明学网同意其观点或证实其描述。

    如何使用跟贴
    修改昵称 关闭窗口
    盖楼回复 关闭窗口
    点击登录 |
    发言 | 退出
    复制收藏 关闭窗口

    复制成功,按CTRL+V发送给好友、论坛或博客。 浏览器限制,请复制链接和标题给好友、论坛或博客。


    最新新闻

        
    新闻-手机-汽车-游戏-家电-家居-女人-音效-欣赏-硬件-企业-网吧-图标-矢量-源码-模板-软件-图库-书籍-笑话-书法-美食-字体-壁纸-问吧-分享
    About US - 关于我们 - 联系方法 - 招聘信息 - 本网声明 - 广告服务 - 网站地图
    中国学网版权所有
    ©2012