Home > Backend Development > PHP Tutorial > Stored in a format used by the web. PHP implements code to classify and store images according to creation time.

Stored in a format used by the web. PHP implements code to classify and store images according to creation time.

WBOY
Release: 2016-07-29 08:41:37
Original
1240 people have browsed it

Copy the code The code is as follows:


/*
Code function: Use PHP to cleverly classify and store images according to their creation time;
The image file attribute must cancel the read-only attribute, otherwise it cannot be deleted
By lost63
*/
//Delay setting
set_time_limit(0);
$path='C:Restore file graphics $picture JPEG image (.jpg)';
$result=dir($path);
while( $value=$result->read()){
if(strpos($value,'.JPG')==true||strpos($value,'.jpg')==true||strpos($value ,'.gif')==true||strpos($value,'.png')==true){
//If the folder does not exist, create it;
$fileNewPath=$path.'\'.fileTime( $path.'\'.$value);
if(!file_exists($fileNewPath)){
mkdir($fileNewPath);
}
moveFile($path.'\'.$value,$fileNewPath.'\' .$value);
}
}
//Get the file modification time
function fileTime($str){
return date("Y-m-d",filemtime($str));
}
//Move the file to a new address
function moveFile($file,$path){
copy($file,$path);
echo $file.'Location update completed
';
unlink($file);
echo $file.'Original position File deleted';
}
?>

The above introduces the implementation code for PHP to classify and store images according to creation time when stored in the format used by the web, including the content of storage in the format used by the web. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template