-
您當(dāng)前所在位置:首頁 → 網(wǎng)絡(luò)編程 → PHP編程 → PHP采集圖片實(shí)例(PHP采集)
PHP采集圖片實(shí)例(PHP采集)
時(shí)間:2015/6/28來源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評(píng)論(0)
-
<?php /** * 采集圖片php程序 * * Copyright(c) 2008 by 小超(ccxxcc) All rights reserved * * To contact the author write to {@link mailto:[email protected]} * * @author ccxxcc * @version $Id: {filename},v 1.0 {time} $ * @package system */
set_time_limit(0); /** * 寫文件 * @param string $file 文件路徑 * @param string $str 寫入內(nèi)容 * @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); } } } }
/** * 從文本中取得一維數(shù)組 * * @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列表文本文件 每個(gè)圖片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>');
?>
|
關(guān)鍵詞標(biāo)簽:采集,實(shí)例,圖片,ifp,v
相關(guān)閱讀
-
熱門文章
plsql developer怎么連接數(shù)據(jù)庫(kù)-plsql deve2021年最好用的10款php開發(fā)工具推薦在 PHP 中使用命令行工具php應(yīng)用程序安全防范技術(shù)研究
人氣排行
詳解ucenter原理及第三方應(yīng)用程序整合思路、方法PHP中防止SQL注入攻擊PHP會(huì)話Session的具體使用方法解析PHP運(yùn)行出現(xiàn)Notice : Use of undefined constant 的解決辦法CakePHP程序員必須知道的21條技巧PHP如何清空mySQL數(shù)據(jù)庫(kù)PHP采集圖片實(shí)例(PHP采集)plsql developer怎么連接數(shù)據(jù)庫(kù)-plsql developer連接數(shù)據(jù)庫(kù)方法