Download Photoshop software with PHP implementation of the code to download the image in the CSS file

Source: Internet
Author: User
Tags create directory
As a veteran and professional Mr Skinner staff, I have accumulated a wealth of Mr Skinner experience since I began to invest in the great Internet from third day. I believe that every programmer who does the web will have a similar experience.
In the Mr Skinner process, it is essential to download the picture in the style file. When you encounter a larger style file, which may have hundreds of images to download, it is most appropriate to use this little code.

Copy the Code code as follows:


< PHP
/*
More & Original PHP framwork
Copyright (c) 2007-2008 Ismole Inc.
Author:kimi
Documentation: Download the picture in the style file, water special Mr Skinner tool
*/
Note Set PHP timeout time
Set_time_limit (0);
Note Get style file content
$styleFileContent = file_get_contents (' images/style.css ');
Note matches the URL address that needs to be downloaded
Preg_match_all ("/url\ (. *) \)/", $styleFileContent, $imagesURLArray);
Note loops need to download the address, download it individually
$imagesURLArray = Array_unique ($imagesURLArray [1]);
foreach ($imagesURLArray as $imagesURL) {
File_put_contents (basename ($imagesURL), file_get_contents ($imagesURL));
}


The above is reproduced in the original text, the following is a revised version, reproduced the words please leave a link.

Copy the Code code as follows:


!--? php set_time_limit (0);
$styleFileContent = file_get_contents (' http://img.jb51.net/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://www.jb51.net/'. $imagesURL;
File_put_contents (basename ($imagesURL), file_get_contents ($imagesURL));
}
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;
}
?>

The above describes the download Photoshop software with PHP implementation of the download CSS files in the image of the code, including the download of Photoshop software content, I hope to be interested in PHP tutorial friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.