Advertisement
michaelyuen

Untitled

Dec 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. // delete all files from new/new/uploads/newfiles first
  3.  
  4. ini_set('display_errors',1); // enable php error display for easy trouble shooting
  5. error_reporting(E_ALL); // set error display to all
  6.  
  7. $imagepath = 'new/new/uploads';
  8. $newfilepath = 'new/new/newuploads';
  9. if (file_exists($newfilepath) === false) {
  10. mkdir($path, 0777, true);
  11. }
  12. $log = $newfilepath . "/log.txt";
  13. $images = GLOB($imagepath . "/" . "*{.jpg,.jpeg,.png,.gif}", GLOB_BRACE);
  14. foreach ($images as $img) {
  15. $oldfilename = basename($img);
  16. $newfilename = preg_replace("/[\s_]/", "-", $oldfilename); // replace space with dash
  17. if (rename($img, $newfilepath . '/' . $newfilename)) {
  18. $data = "original file: {$img} to: {$newfilename} status: Successful\r\n";
  19. } else {
  20. $data = "original file: {$img} to: {$newfilename} status: Fail\r\n";
  21. }
  22. file_put_contents($log, $data, FILE_APPEND); // create log file
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement