问题
A Client of me had the follwing Problem:
He has a Webcam that Uploads Pictures to a FTP Folder.
Unfortunaly the Webcam does Upload each File seperatly (Webcam_Eglisauxxxxxx.jpg) xxxxx stands for a Timestamp from the Webcam. There is no Way to achive that the Webcam by herself just overrides the latest file :(
Now i Need a php script to check against new Files in this Directory and rename it to a given Name. (Webcam_Eglisau_Image.jpg)
I know that this Need the rename function but i have no Idea how i can search for a not know Name (the xxxxxx) in the File.
The .php File will be located in the same Dir as the Pictures...
Any Ideas?
I would like to run this script after with a Cron Job :)
Thanks
回答1:
You can use
$fileList = glob('Webcam_Eglisau*.jpg');
var_dump($fileList);
It gives you all Files Webcam_Eglisau * .jpg Then you can rename the one which is called xxxxxxx (the newest)
Update:
foreach (glob("Webcam_Eglisau*.jpg") as $filename) {
echo "Renaming " . $filename . " now.</br>";
$uniqid = uniqid();
if(file_exists($filename)) {
rename($filename, "Webcam_Eglisau_" . $uniqid . ".jpg");
echo $filename . " is now Webcam_Eglisau_" . $uniqid . ".jpg</br>";
}
}
回答2:
So if i have a .php in the same Directory as the Uploaded Files i can use:
<?php $fileList = glob('Webcam_Eglisau*.jpg');
var_dump($fileList);
rename ( $fileList, "/Webcam_Eglisau_Image.jpg");
?>
来源:https://stackoverflow.com/questions/30776797/renaming-pictures-on-a-ftp-folder-with-different-names-to-1-file-override-for