


PHP batch download image files in html and css examples_PHP tutorial
The first step to download images in PHP is to use regular expressions to collect the image addresses in the string, and then use PHP related functions to read the images directly and save them to the local server to achieve batch downloading of images.
I have been very busy recently. I encountered a manual job and needed to download some remote pictures. There were more than a hundred pictures in total. It would be too time-consuming to save them one by one manually, so I googled them online. Find a way to download image files in batches with PHP. The original text is an article from Ordinary World Blog about how to use PHP to batch download images in CSS files. After some research and rewriting, it can be used, which is much more convenient and faster.
PHP batch download image file code:
The code is as follows | Copy code | ||||||||
$imagesURLArray = array_unique($imagesURLArray ); echo $imagesURL; echo " "; File_put_contents(basename($imagesURL), file_get_contents($imagesURL));
|
The code is as follows | Copy code |
<🎜>< ?php<🎜> /*<🎜> More & Original PHP Framwork<🎜> Copyright (c) 2007 - 2008 IsMole Inc.<🎜> Author: kimi<🎜> Documentation: Download the pictures in the style file, Shuishui special peeling tool<🎜> */<🎜> <🎜>//note Set 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));<🎜> }<🎜> |
Later I found a php batch download image file
Suppose now I find that the image saving method on a website is 1001 – 1999. There are .jpg images starting from 1 (varying quantities) stored in the directory. Now I decide to use PHP to save the images according to my needs. Styles are downloaded directly to local location
If the starting address of the image is: http://image.xxx.com/img/1001/1.jpg
At this time, I put 1001 in the variable $id, 1.jpg in the variable $num.jpg, and the saved file name is $id_$num.jpg
First make sure to create a writable folder named img under the execution directory of this file
The code is as follows
|
Copy code | ||||
$id= isset($_GET['id']) && intval($_GET['id']) && $_GET['id']>1000 ? $_GET['id'] : 1001;
$num= isset($_GET['num']) && intval($_GET['num']) ? $_GET['num'] : 1; $url="http://image.xxx.com/img/{$id}/{$num}.jpg"; $f=fopen($filename,'a'); fwrite($f,$img); fclose($f);
}else{
$new_url="?id=".($id+1)."&num=1";
}
if($id > 1999) exit('all completed');
//Show current status
echo $url,' - ',$array[0],'<script>location.href="'.$new_url.'";</script>';
http://www.bkjia.com/PHPjc/632712.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632712.htmlTechArticleIn the first step of downloading images in php, I need to use regular rules to collect the image address in the string, and then Then use php related functions to directly read and save the image to the local server...
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.
