Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // delete all files from new/new/uploads/newfiles first
- ini_set('display_errors',1); // enable php error display for easy trouble shooting
- error_reporting(E_ALL); // set error display to all
- $imagepath = 'new/new/uploads';
- $newfilepath = $imagepath . '/newfiles';
- if (file_exists($newfilepath) === false) {
- mkdir($path, 0777, true);
- }
- $log = $newfilepath . "/log.txt";
- $images = GLOB($imagepath . "/" . "*{.jpg,.jpeg,.png,.gif}", GLOB_BRACE);
- foreach ($images as $img) {
- $oldfilename = basename($img);
- $newfilename = preg_replace("/[\s_]/", "-", $oldfilename); // replace space with dash
- if (rename($img, $newfilepath . '/' . $newfilename)) {
- $data = "original file: {$img} to: {$newfilename} status: Successful\r\n";
- } else {
- $data = "original file: {$img} to: {$newfilename} status: Fail\r\n";
- }
- file_put_contents($log, $data, FILE_APPEND); // create log file
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement