michaelyuen

Untitled

Dec 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2. $imagefolder = "";
  3. $images = GLOB($imagefolder . "/" . "*{.jpg,.jpeg,.png,.gif}", GLOB_BRACE);
  4.  
  5. foreach ($images as $img) {
  6.  
  7.     $file = $img;
  8.     $fileparts = pathinfo($file);
  9.     $path = $fileparts['dirname'] . "/newfiles/";
  10.     $newfile = $path . date("Y-m-d", filemtime($img)) . "." . $fileparts['extension'];
  11.     if (!file_exists($newfile)) {
  12.         rename ($file, $newfile);
  13.         $log = $path . "/log.txt";
  14.         $data = "original file: {$file} to: {$newfile} status: Successful";
  15.     } else {
  16.         $data = "original file: {$file} to: {$newfile} status: Error, file exists";
  17.     }
  18.    
  19.     file_put_contents($log, $data, FILE_APPEND); // create log file
  20. }
Add Comment
Please, Sign In to add comment