php批量下载图片
[PHP]代码
假如现在我现在发现一个网站上的图片保存方式是1001 – 1999目录下都存放着从1开始(数量不等)的.jpg图片,现在我决定用php的方法将图片按照自己需要的样式直接下载到本地 假如图片开始地址为:http://www.php.cn/ 这时我将1001处放到变量$id,1.jpg放到变量$num.jpg,保存的文件名为$id_$num.jpg 首先确保在此文件执行目录下面建一个名为img的并且可写的文件夹 <?php $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"; $array=get_headers($url,1); //通过返回200和400来判断是增加$id或者$num if(preg_match('/200/',$array[0])){ $new_url="?id={$id}&num=".($num+1); ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); $filename="./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('全部完成'); //显示当前的状态 echo $url,' - ',$array[0],'<script>location.href="'.$new_url.'";</script>'; ?>

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

AI Hentai Generator
Generate AI Hentai for free.

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
