Home > Backend Development > PHP Tutorial > PHP 将图片按创建时间进行分类存储的实现代码_PHP

PHP 将图片按创建时间进行分类存储的实现代码_PHP

WBOY
Release: 2016-06-01 12:20:06
Original
872 people have browsed it
复制代码 代码如下:
/*
代码功能:使用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.'原位置文件已删除';
}
?>
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