Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 将图片按创建时间进行分类存储的实现代码_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:20:06817Durchsuche
复制代码 代码如下:
/*
代码功能:使用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.'原位置文件已删除';
}
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn