PHP classifies images by creation time to store the implementation code

  • 2020-03-31 20:17:30
  • OfStack


<?php 
 
//Time delay is set
set_time_limit(0); 
$path='C: Restore file graphics $ The 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){ 
//Creates a folder if it does not exist;
$fileNewPath=$path.'\'.fileTime($path.'\'.$value); 
if(!file_exists($fileNewPath)){ 
mkdir($fileNewPath); 
} 
moveFile($path.'\'.$value,$fileNewPath.'\'.$value); 
} 
} 
//Gets the file modification time
function fileTime($str){ 
return date("Y-m-d",filemtime($str)); 
} 
//Move the file to the new address
function moveFile($file,$path){ 
copy($file,$path); 
echo $file.' Location update completed <br>'; 
unlink($file); 
echo $file.' The original location file has been deleted '; 
} 
?>

Related articles: