Renaming Pictures on a FTP Folder with different Names to 1 File (Override) for a Webcam Feed

491 views Asked by At

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

2

There are 2 answers

0
Devsome On BEST ANSWER

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>";
  }
}
0
Marcel Spühler On

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");
?>