Author Topic: Image Rename Script Help **Solved**  (Read 641 times)

0 Members and 1 Guest are viewing this topic.

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Image Rename Script Help **Solved**
« on: October 14, 2017, 04:32:27 AM »
Hi,

I'm trying to get image_rename script to work, I've tried numerous permutations but have conceded defeat.

I have a Foscam F19901EP set to FTP a snapshot to x10hosting test site and would like the script to generate a standard.jpg name.

Any help apreachiated as always

Ian


Error messages http://chatteris.x10host.com//FI9901EP_00626E70E4DF/image_rename.php
« Last Edit: October 15, 2017, 11:34:51 AM by Ian. »
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #1 on: October 14, 2017, 09:00:04 AM »
Can you post the script without your modifications?

And, may I ask, why do you need a script like that? Why not simple scan the upload folder and sort the images (by filename) to show the latest image ? (Guess you are looking for at static filename to use in your html?)

Regards
« Last Edit: October 14, 2017, 09:20:20 AM by droiddk »

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #2 on: October 14, 2017, 09:30:45 AM »
Hi,

I've attached the file, I copied this from wxforum and includes modifications to make it work with version 7 php which Jachym worked on and the forum member with the issue reported back that it all works.


CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #3 on: October 14, 2017, 10:31:10 AM »
And second question ?  :grin:

Offline PaulMy

  • Forecaster
  • *****
  • Posts: 3643
    • KomokaWeather
Re: Image Rename Script Help
« Reply #4 on: October 14, 2017, 11:05:16 AM »
Hi Ian,
Not sure if this will help as my HV failed and haven't replaced it and was not using PHP7, but I worked with morfeas2002 on that script and it worked fine for me - even though I didn't understand the code.
In comparing your attached script to mine I see some differences:

Your line 11: $dir = "../FI9901EP_00626E70E4DF"; // change to suit your system relative to where this script is executed
Mine line 15: $dir = "../hvipupload"; // change to suit your system relative to where this script is executed
and that should be fine.

Your line 20: if (preg_match('/^\.{1,2}$/',$fname)) continue;
Mine line 25: if (ereg('^\.{1,2}$',$fname)) continue;

Your line 22: if (! preg_match('/\.(JPG)$/',$fname)) continue;
Mine line 27: if (! ereg($pattern,$fname)) continue;
and the above 2 differences could be PHP 7 requirement

Your line 41: copy("/snap/$newname", "/new/webcamimage.jpg"); // change to suit your system relative to where this script is executed
Mine line 50: copy("../hvipupload/$newname", "../hvipimage/hvipimage.jpg"); // change to suit your system relative to where this script is executed
where my defined $dir = "../hvipupload" in line 15 is used in line 50, your line 41 is different than in line 11

My webserver structure was?
/pictures/hvip/hik.php  (my name change script)
/pictures/hvipupload/  (where the date/time stamped image was FTP and which was emptied at each run of the rename script)
/pictures/hvipimage/hvipimage.jpg  (the renamed current time image)

Darn, I wish that camera still worked http://www.komokaweather.com/pictures/hvipimage/hvipimage.jpg
Enjoy,
Paul

EDIT: after I typed my reply and posted I noticed you had also posted my script in full ;)

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #5 on: October 14, 2017, 12:36:33 PM »
Hi Paul,

Many thanks for all the effort you have put in on this, I'm blowed if I can get it to work.

When I run the script which I have called foscam.php it throws up the following error message:

Warning: sort() expects parameter 1 to be array, null given in /home/chatteri/public_html/foscam.php on line 37

Warning: copy(): The first argument to copy() function cannot be a directory in /home/chatteri/public_html/foscam.php on line 50

Some good news is that the .jpg file which the camera uploads to the snap sub directory is being erased when the script is ran, but this does not generate a new foscamimage1.jpg in my case.

I've attached the modified script which should have followed your information, I've added notes in the document to highlight chnages.

I never have been any good at relitive and absolute paths, and so far filezilla transfer count with me trying to get this working has hit 45 lol

Ian


New link to script - http://chatteris.x10host.com/foscam.php
« Last Edit: October 14, 2017, 01:07:22 PM by Ian. »
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #6 on: October 14, 2017, 12:59:05 PM »
I guess you will not reply to my second question so good luck!


Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #7 on: October 14, 2017, 01:05:25 PM »
Sorry droidk I didn't see the second part of your first reply.

Yes you are correct, I need a fixed image name so that I can link to it, unfortunaltly the webcam only uplads day, date, year time format.

Please dont be offended, I genuinly did not see the second part.

Ian
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #8 on: October 14, 2017, 01:10:20 PM »
Sorry droidk I didn't see the second part of your first reply.

Yes you are correct, I need a fixed image name so that I can link to it, unfortunaltly the webcam only uplads day, date, year time format.

Please dont be offended, I genuinly did not see the second part.

Ian

Its okay Ian, I just want to help you  :grin:

For the same situation I just use this very simple vode:

<?php

$dirname = "images/";

if ($images = glob($dirname."*.jpg") ) {

  rsort($images);

  $img = $images[0];

  echo  "<img src=\"$img\">";

}

?>

That script will find all the jpg's in the "images" folder and show the latest image.
Maybe you can use it.

Kind Regards
droid
« Last Edit: October 14, 2017, 01:27:47 PM by droiddk »

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #9 on: October 14, 2017, 01:15:37 PM »
Thanks droiddk,

As you can proberbly tell I'm not a scripter  :oops:  , how would I impliment your code, my webcam is sending a new image ebery 5 minutes to a folder: /FI9901EP_00626E70E4DF/snap
this is embedded in the camera firmware so I can't change this.

What do you suggest that I can try?

tnx Ian
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #10 on: October 14, 2017, 01:19:15 PM »
Thanks droiddk,

As you can proberbly tell I'm not a scripter  :oops:  , how would I impliment your code, my webcam is sending a new image ebery 5 minutes to a folder: /FI9901EP_00626E70E4DF/snap
this is embedded in the camera firmware so I can't change this.

What do you suggest that I can try?

tnx Ian

Hi Ian

The page where you want to show your image, is that a php-page?

Regards
Droid

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #11 on: October 14, 2017, 01:35:25 PM »
Hi again Ian

You can try making a php file with this code:

<?php

if ($images = glob("*.jpg") ) {

  rsort($images);

  $img = $images[0];

  echo  "<img src=\"$img\">";

}

?>

Place the new file in the folder with your images.

When you are loading that new file in your browser the latest image should be on screen. Just as a test.

Regards
Droid
« Last Edit: October 14, 2017, 01:38:24 PM by droiddk »

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #12 on: October 14, 2017, 01:42:43 PM »
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline PaulMy

  • Forecaster
  • *****
  • Posts: 3643
    • KomokaWeather
Re: Image Rename Script Help
« Reply #13 on: October 14, 2017, 01:48:50 PM »
The droiddk suggestions is working... great!  I presume that keeps all the images in the /snap folder without doing any erasing, nice!
 
Quote
Some good news is that the .jpg file which the camera uploads to the snap sub directory is being erased when the script is ran, but this does not generate a new foscamimage1.jpg in my case.
which is good and presume on the right track for that script.

Quote
Warning: sort() expects parameter 1 to be array, null given in /home/chatteri/public_html/foscam.php on line 37
Warning: copy(): The first argument to copy() function cannot be a directory in /home/chatteri/public_html/foscam.php on line 50
Sorry I don't know what would be needed to overcome this.

Quote
I never have been any good at relitive and absolute paths, and so far filezilla transfer count with me trying to get this working has hit 45 lol
If foscam.php is in your /public_html folder I wonder if the path to $dir = "./FI9901EP_00626E70E4DF"; // change to suit your system relative to where this script is executed
should be $dir = "/FI9901EP_00626E70E4DF"; // change to suit your system relative to where this script is executed
but presume you have already tried numerous versions of the path... in line15 and 50.

Regards,
Paul

 

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #14 on: October 14, 2017, 01:49:58 PM »
Hi,

Yep that displays  :lol::

http://chatteris.x10host.com//FI9901EP_00626E70E4DF/snap/camtest.php


Ian

Great.

Now, in your php file where you want to show your image put in this:

<?php

$dirname = "images/";

if ($images = glob($dirname."*.jpg") ) {

  rsort($images);

  $img = $images[0];

  echo  "<img src=\"$img\">";

}

?>

And change $dirname = "images/"; to suit your setup. If page with the image is in root-folder and images are in root/snap then change it to $dirname = "snap/";

Let me know :-D

Kind Regards
« Last Edit: October 14, 2017, 01:51:53 PM by droiddk »

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #15 on: October 14, 2017, 01:51:13 PM »
I presume that keeps all the images in the /snap folder without doing any erasing.

Yes  :grin:

Kind Regards


Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #16 on: October 14, 2017, 02:01:24 PM »
If you want you can split it like this:

This at the beginning of the php file:

<?php

$dirname = "images/";

if ($images = glob($dirname."*.jpg") ) {

  rsort($images);

  $img = $images[0];

}

?>

And this where you want to show the image:

 <?php echo  "<img src=\"$img\">"; ?>

Regards
Droid

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #17 on: October 14, 2017, 02:11:16 PM »
Hi Droiddk,

My main webhost is GoDaddy, I'm using x 10 so I can play without breaking anything, so the main php scripts (Saratoga & Meteotemplate) for displaying images are on that host, I can change the FTP of the camera and move the work done so far which isn't a problem, I can see how you are moving me forward which is brilliant, is it possible to chnage to a fixed file name at this point without moving over to Go Daddy, if not, I'll start making the changes if its all part of a bigger plan.

Ian
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #18 on: October 14, 2017, 02:18:29 PM »
Hi Ian

I'm not sure I understand your last question  :oops:

If you can send me the php file and mark the place in that file where the image shall show, and also send me a screenshot showing the folder structure on the web-server I can try making it for you.

Note that you can change the width and height like this:

"<img src=\"$img\" alt=\"My Image\" height=\"42\" width=\"42\" >";

Regards
Droid
« Last Edit: October 14, 2017, 02:20:32 PM by droiddk »

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #19 on: October 14, 2017, 02:19:57 PM »
The droiddk suggestions is working... great!  I presume that keeps all the images in the /snap folder without doing any erasing, nice!
 
Quote
Some good news is that the .jpg file which the camera uploads to the snap sub directory is being erased when the script is ran, but this does not generate a new foscamimage1.jpg in my case.
which is good and presume on the right track for that script.

Quote
Warning: sort() expects parameter 1 to be array, null given in /home/chatteri/public_html/foscam.php on line 37
Warning: copy(): The first argument to copy() function cannot be a directory in /home/chatteri/public_html/foscam.php on line 50
Sorry I don't know what would be needed to overcome this.

Quote
I never have been any good at relitive and absolute paths, and so far filezilla transfer count with me trying to get this working has hit 45 lol
If foscam.php is in your /public_html folder I wonder if the path to $dir = "./FI9901EP_00626E70E4DF"; // change to suit your system relative to where this script is executed
should be $dir = "/FI9901EP_00626E70E4DF"; // change to suit your system relative to where this script is executed
but presume you have already tried numerous versions of the path... in line15 and 50.

Regards,
Paul

Hi Paul,

Your help has been great, it looks like I'm on the way with getting this sorted, I have two differnt ipcams which I will be using the finished script on so its worth the pain.

Hope you manage to get a new camera soon, Christmas isn't a million miles away :-)

All the best

Ian
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #20 on: October 14, 2017, 02:22:20 PM »
Hi Ian

I'm not sure I understand your last question  :oops:

If you can send me the php file and mark the place in that file where the image shall show, and also send me a screenshot showing the folder structure on the web-server I can try making it for you.

Note that you can change the width and height like this:

"<img src=\"$img\" alt=\"My Image\" height=\"42\" width=\"42\" >";

Regards
Droid

Hi Droid,

I'll start moving files and make camera FTP changes, I'll post up with progress as quick as I can

Ian
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Image Rename Script Help
« Reply #21 on: October 14, 2017, 02:29:31 PM »

Hi Droid,

I'll start moving files and make camera FTP changes, I'll post up with progress as quick as I can

Ian

Oki, good luck  :grin: Remember backup all files.

Regards
Droid

Offline PaulMy

  • Forecaster
  • *****
  • Posts: 3643
    • KomokaWeather
Re: Image Rename Script Help
« Reply #22 on: October 14, 2017, 02:39:11 PM »
Thanks Ian,
Quote
Hope you manage to get a new camera soon, Christmas isn't a million miles away :-)
It's the climbing on the roof, setting up the camera FTP and in the router, etc. that is holding me back...  I did it once and remember the pain.

Paul


Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #23 on: October 14, 2017, 03:45:09 PM »
OK Stuck! my new Foscam F19901EP wont FTP to GoDaddy for some reason, so to move this on....

Recap -
webcam uploading images every 5 mins to server
Script to display latest image works fine - http://chatteris.x10host.com//FI9901EP_00626E70E4DF/snap/camtest.php

Issues to resolve -

Delete images which are earlier than the latest one
Rename latest image so that it can be pointed to by WU and external users (including my web site in the short term).


CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz

Offline Ian.

  • Forecaster
  • *****
  • Posts: 379
    • Chatteris Weather
Re: Image Rename Script Help
« Reply #24 on: October 15, 2017, 03:47:07 AM »
Ok new day new start....and many thanks for all the help and suggestions so far..

Going back to basics to get the original script working for me, Paul described his config which worked for him when his camera was available... so I mimiced his setup on the server and the script, thinking if I can at least get it working that way, I can incrementally make the changes to suit the foscam:

I have

/pictures/hvip/hik.php
/pictures/hvipimage
/pictures/hvipupload

A test image named hvipimage.jpg in the hvipimage sub directory
A test image with a date/time name in the hvipupload sub directory

Running the script clears the contents of hvipupload, but does not update the image in hvipimage, also an error message is generated:

Warning: sort() expects parameter 1 to be array, null given in /home/chatteri/public_html/pictures/hvip/hik.php on line 37

Warning: copy(): The first argument to copy() function cannot be a directory in /home/chatteri/public_html/pictures/hvip/hik.php on line 50


This is the script I'm trying to work:

Code: [Select]
<?php
#############################################################################################################
## Script to rename Hikvision IP uploaded files containing date and time in file name to a new fixed filename
## Provided by morfeas2002  http://kalamata.meteoclub.gr/

## CAUTION this script will remove any ???.jpg uploaded files from the folder
## CAUTION
## CAUTION
## CAUTION this script will remove any ???.jpg uploaded files from the folder
#############################################################################################################

date_default_timezone_set("Europe/London"); // 
//
//
$dir "../hvipupload"// change to suit your system relative to where this script is executed
// changed from "../hvipupload"
$pattern '\.(jpg)$';
//
$newstamp 0;           
$newname "";

if (
$handle opendir($dir)) {              
       while (
false !== ($fname readdir($handle)))  {           
         
// Eliminate current directory, parent directory           
         
if (preg_match('/^\.{1,2}$/',$fname)) continue;           
         
// Eliminate other pages not in pattern           
         
if (! preg_match('/\.(JPG)$/',$fname)) continue;           
         
// -------------
         //
         //
        
         //
         
$pinakas[] = $fname;
       }
       
//
       //
       
sort($pinakas);
 // 
       
$posot count($pinakas);
       
//
       
if ($posot>1$newname $pinakas[$posot-2];
       if (
$posot==1$newname $pinakas[$posot-1];

}
closedir ($handle);

// $newname
//

copy("../hvipupload/$newname""../hvipimage/hvipimage.jpg"); // change to suit your system relative to where this script is executed
// changed from "../hvipupload/$newname", "../hvipimage/hvipimage.jpg" but had to add $dir from line 15
//

$filesa glob('../hvipupload/*.jpg'); // change to suit your system relative to where this script is executed
// not sure what to enter here?
array_walk($filesa,'myunlink');

function 
myunlink($t)
{
unlink($t);
}

?>


What am I missing (apart form the obvious lack of scripting knowledge)!

Ian
CWOP - DW3371
PWS - ICAMBRID16
https://www.chatteris.biz