Implementation code for php to download images in css files
Release: 2016-07-25 08:52:27
Original
1051 people have browsed it
-
-
/* - More & Original PHP Framwork
- Copyright (c) 2007 - 2008 IsMole Inc.
Author: kimi
- Documentation : Download the pictures in the style file, Shuishui’s special peeling tool
- */
//note Set the PHP timeout
- set_time_limit(0);
// note Get the content of the style file
- $styleFileContent = file_get_contents('images/style.css');
//note Match the URL address that needs to be downloaded
- preg_match_all("/url((.* ))/", $styleFileContent, $imagesURLArray);
//note Loop through the addresses to be downloaded and download them one by one
- $imagesURLArray = array_unique($imagesURLArray[1]);
- foreach($ imagesURLArray as $imagesURL) {
- file_put_contents(basename($imagesURL), file_get_contents($imagesURL));
- }
Example 2, modified version:
- set_time_limit (0) ;
- $styleFileContent = file_get_contents ( 'http://img.jbxue.com/skin/newblue/main.css' );
- preg_match_all ( "/url((.*))/", $styleFileContent, $imagesURLArray );
- $imagesURLArray = array_unique ( $imagesURLArray [1] );
- foreach ( $imagesURLArray as $imagesURL ) {
- $dir=dirname($imagesURL);
- if(!file_exists($dir))
- {
- //Create directory
- createDir($dir);
- }
- $imagesURL='http://bbs.it-home.org/'.$imagesURL;
- file_put_contents ( basename ( $imagesURL ), file_get_contents ( $imagesURL ) );
- }< ;/p>
function createDir($path) {
- $path = str_replace('\','/',$path) ;
- if ( is_dir($path) ) return true ;
- if ( file_exists ($path) ) return false ;
$parent = substr($path ,0, strrpos($path,'/') ) ;
- if ( $parent==='' | | $parent==='.' || createDir( $parent ) )
- return @mkdir($path) ;
- else return false ;
- }
- ?>
-
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31