PHP 将图片按创建时间进行分类存储的实现代码
复制代码 代码如下:
/*
代码功能:使用PHP巧妙将图片按创建时间进行分类存储;
图片文件属性须取消只读属性,否则无法删除
By lost63
*/
//延时设置
set_time_limit(0);
$path='C:\恢复文件\图形$图片\JPEG 图像 (.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){
//如果文件夹不存在则建立;
$fileNewPath=$path.'\\'.fileTime($path.'\\'.$value);
if(!file_exists($fileNewPath)){
mkdir($fileNewPath);
}
moveFile($path.'\\'.$value,$fileNewPath.'\\'.$value);
}
}
//取得文件修改时间
function fileTime($str){
return date("Y-m-d",filemtime($str));
}
//移动文件至新地址
function moveFile($file,$path){
copy($file,$path);
echo $file.'位置更新完成
';
unlink($file);
echo $file.'原位置文件已删除';
}
?>

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

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

SublimeText3 Linux new version
SublimeText3 Linux latest version