Advertisement
michaelyuen

Untitled

Dec 25th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors',1); // enable php error display for easy trouble shooting
  3. error_reporting(E_ALL); // set error display to all
  4.  
  5. $imagefolder = "new/new/uploads";
  6. $images = GLOB($imagefolder . "/" . "*{.jpg,.jpeg,.png,.gif}", GLOB_BRACE);
  7.  
  8. foreach ($images as $img) {
  9.  
  10.     $file = $img;
  11.     $fileparts = pathinfo($file);
  12.     $path = $fileparts['dirname'] . "/newfiles";
  13.         if (file_exists($path) === false) {
  14.             mkdir($path, 0777, true);      
  15.         }
  16.  
  17.     $newfile = $path . '/'. date("Y-m-d", filemtime($img)) . "." . $fileparts['extension'];
  18.     if (!file_exists($newfile)) {
  19.         rename ($file, $newfile);
  20.         $log = $path . "/log.txt";
  21.         $data = "original file: {$file} to: {$newfile} status: Successful";
  22.     } else {
  23.         $data = "original file: {$file} to: {$newfile} status: Error, file exists";
  24.     }
  25.     file_put_contents($log, $data, FILE_APPEND); // create log file
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement