php采集图片列表,PHP采集图片实例(PHP采集)

以下为引用的内容:

/**

*  采集图片php程序

*

*  Copyright(c) 2008 by 小超(ccxxcc) All rights reserved

*

*  To contact the author write to [email protected] mailto:[email protected]}

*

* @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("$path_get can not get");

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(‘

无链接地址
‘);

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(‘

finish
‘);

?>

著作权归作者所有。

商业转载请联系作者获得授权,非商业转载请注明出处。

作者:站长之家编辑

链接:https://www.chinaz.com/program/2008/1017/41142.shtml

来源:站长之家

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值