WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: tripper22 on November 12, 2017, 04:32:52 PM

Title: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 12, 2017, 04:32:52 PM
Since Weather Underground is no longer going to be hosting webcam images I have to do it myself. I currently use GoDaddy to host a Worpress website and I want to use a page of that website to display static images that are uploaded every 10 minutes.

So far:

-Camera is uploading images in nested folders every 10 minutes.
-I need a script that takes the latest *jpg image from the folders to create a current static image with a consistent name.

A user @Ian. with similar issues posted his problem which is similar to mine here. http://www.wxforum.net/index.php?topic=33009.0

I did everything I could following the different instructions from that thread. I have the same error he encountered but I can't resolve it, even though he did.

The errors:

Warning: sort() expects parameter 1 to be array, null given in /home/content/45/3170445/html/krb/wp-content/uploads/webcam//hik.php on line 37

Warning: copy(): The first argument to copy() function cannot be a directory in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/hik.php on line 50

Any help would be greatly appreciated. :)





Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Ian. on November 12, 2017, 05:03:55 PM
I've replied to your PM.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 12, 2017, 06:04:02 PM
I am making progress. The reason why it's not working is because the .jpg is not in the root of the upload folder. If I put a .jpg file in the root of upload folder it works fine. It won't work if the .jpg is within folders within the upload folder. The Amcrest camera uploads the images into nested folders and there is no way to change it. I need to find a way to move the newest jpg file from the nested folders and preferably delete everything in there afterwards (files are named 01[R][0@0][0].jpg).

The Wunderground ftp made it work so there must be a way.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 05:48:25 AM
Hi,
I guess I have too little info, I need to know exactly what you are trying to achieve, how the folders are structured, the paths etc.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 12:55:51 PM
Okay I will be as detailed as I can be. The camera is an Amcrest IP2M-841. I am using Godaddy's Linux hosting. The camera uploads a jpg image to the server every 10 minutes.

The current file structure:
/webcam/AMC000X5_3R286G/2017-11-11/001/jpg/17/40/01[R][0@0][0].jpg
                                                                               /50/01[R][0@0][0].jpg
                                                                         /18/00/01[R][0@0][0].jpg
                                                                              /10/01[R][0@0][0].jpg
                                                                              /20/01[R][0@0][0].jpg
                                                                              /30/01[R][0@0][0].jpg

I want to rename the newest jpg image to image.jpg and move it to the root of the webcam folder and delete the old files periodically. I attached the php script that I got from Ian's thread. I created the folders in that script to test and see if it works and it does. But it won't work of course with my file structure. Because the script needs a jpg file in the root of the folder. Hopefully that was descriptive enough. :) Thanks!
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 01:17:37 PM
The problem is that your cam creates new folders for even every minute
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 13, 2017, 01:36:51 PM
Okay I will be as detailed as I can be. The camera is an Amcrest IP2M-841. I am using Godaddy's Linux hosting. The camera uploads a jpg image to the server every 10 minutes.

The current file structure:
/webcam/AMC000X5_3R286G/2017-11-11/001/jpg/17/40/01[R][0@0][0].jpg
                                                                               /50/01[R][0@0][0].jpg
                                                                         /18/00/01[R][0@0][0].jpg
                                                                              /10/01[R][0@0][0].jpg
                                                                              /20/01[R][0@0][0].jpg
                                                                              /30/01[R][0@0][0].jpg

I want to rename the newest jpg image to image.jpg and move it to the root of the webcam folder and delete the old files periodically. I attached the php script that I got from Ian's thread. I created the folders in that script to test and see if it works and it does. But it won't work of course with my file structure. Because the script needs a jpg file in the root of the folder. Hopefully that was descriptive enough. :) Thanks!

uff, crazy structure. No chance you can change that? Changing it would be the "easy" thing to do.

Edit: https://amcrest.com/forum/technical-discussion-f3/ftp-snapshot-folders-t2705.html

Regards
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 01:43:46 PM
The problem is that your cam creates new folders for even every minute
I guess it's whatever time the user sets the snapshot time to be. The file structure cannot be changed. The Weather Underground ftp would grab the newest image from the folders and move it so it could be displayed on their website. There must be a way...
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 01:46:07 PM
Okay I will be as detailed as I can be. The camera is an Amcrest IP2M-841. I am using Godaddy's Linux hosting. The camera uploads a jpg image to the server every 10 minutes.

The current file structure:
/webcam/AMC000X5_3R286G/2017-11-11/001/jpg/17/40/01[R][0@0][0].jpg
                                                                               /50/01[R][0@0][0].jpg
                                                                         /18/00/01[R][0@0][0].jpg
                                                                              /10/01[R][0@0][0].jpg
                                                                              /20/01[R][0@0][0].jpg
                                                                              /30/01[R][0@0][0].jpg

I want to rename the newest jpg image to image.jpg and move it to the root of the webcam folder and delete the old files periodically. I attached the php script that I got from Ian's thread. I created the folders in that script to test and see if it works and it does. But it won't work of course with my file structure. Because the script needs a jpg file in the root of the folder. Hopefully that was descriptive enough. :) Thanks!

uff, crazy structure. No chance you can change that? Changing it would be the "easy" thing to do.

Edit: https://amcrest.com/forum/technical-discussion-f3/ftp-snapshot-folders-t2705.html

Regards

There is no way to change it. But it's exactly the same as the link you provided droid.  Like I said to Jachym above: The Weather Underground ftp would grab the newest image from the folders and move it so it could be displayed on their website. There must be a way...
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 13, 2017, 01:47:30 PM
Can you pull a image directly from the camera:
http://[ip]/cgi-bin/snapshot.cgi?loginuse=[USERNAME]&loginpas=[PASSWORD]

Remove [] and insert info.

?
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 01:50:42 PM
I guess some complex iteration could do this, but you would basicaly have to blindly scan all the possible files/folders (0-23) and for each (0-59) and then check the latest and meanwhile save the image names and then delete them and then delete the folders. The script I originally posted that can get the latest image definitely cannot do this, you would have to have a completely different PHP script for this and question is how fast it would be given all the iterations
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 13, 2017, 01:52:23 PM
I guess some complex iteration could do this, but you would basicaly have to blindly scan all the possible files/folders (0-23) and for each (0-59) and then check the latest and meanwhile save the image names and then delete them and then delete the folders. The script I originally posted that can get the latest image definitely cannot do this, you would have to have a completely different PHP script for this and question is how fast it would be given all the iterations

I agree.

Regards
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 01:53:29 PM
Can you pull a image directly from the camera:
http://[ip]/cgi-bin/snapshot.cgi?loginuse=[USERNAME]&loginpas=[PASSWORD]

Remove [] and insert info.

?

I cannot. The camera is in a remote location using a satellite internet connection behind a double nat.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 01:56:05 PM
I guess some complex iteration could do this, but you would basicaly have to blindly scan all the possible files/folders (0-23) and for each (0-59) and then check the latest and meanwhile save the image names and then delete them and then delete the folders. The script I originally posted that can get the latest image definitely cannot do this, you would have to have a completely different PHP script for this and question is how fast it would be given all the iterations

Maybe that's part of the reason why Weather Underground is going to do away with the webcams. I guess i'm hooped :-(
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 13, 2017, 01:59:17 PM
I cannot. The camera is in a remote location using a satellite internet connection behind a double nat.

Ok.
Cant come up with a easy fix.

Regards
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 02:50:52 PM
It is normally not that difficult to do, however the structure you have on your server makes it quite complex and would require several nested loops
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 03:01:25 PM
Thanks Jachym. I guess I will have to buy a new camera.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: bchwdlks on November 13, 2017, 03:05:38 PM
Can you put another ip device at your remote location ? If so you have an easy fix:

Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 13, 2017, 03:07:29 PM
01[R][0@0][0].jpg  is that the actual name of the file? (example)

Regards

Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 03:49:44 PM
Can you put another ip device at your remote location ? If so you have an easy fix:

  • put a raspberry pi on the remote network
  • collect the images from the camera on the raspberry
  • watch the image directory on the raspberry with inotifywait
  • when it sees a new image let the raspberry ftp it to your web server with any name that works

Thanks bch. I was hoping I wouldn't have to go out there. It's a long way. It's possible. I have an older Raspberry Pi lying around. Is there a tutorial that you know of that I can use?
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 03:50:57 PM
01[R][0@0][0].jpg  is that the actual name of the file? (example)

Regards

Yes every time from what I can see.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 13, 2017, 03:51:46 PM

Yes every time from what I can see.

Ok. I have never seen anything like that before  :shock:

Regards
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: SteveFitz1 on November 13, 2017, 04:14:59 PM
Have you considered using a small DOS batch script to save an image, then turn around and FTP it to your website in the same script? You could use Windows Task Scheduler to kick off this batch job at whatever interval you want to update the image.

Steve
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 04:33:06 PM
Thanks Steve. The camera is in a remote location that won't allow for a windows box unfortunately.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 04:41:21 PM
Maybe a for loop that would look for every hour (0-23) and nested loop for each hour (0-59) and then get the folder content via the glob function and then save them all in an array, sort it and find the latest. Then delete the files, though this is even trickier because PHP cannot delete a folder unless it is empty, so you would need to delete the individual files, then delete the "minute" folder, once it is empty, delete the "hour" folder
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 04:50:12 PM
Maybe a for loop that would look for every hour (0-23) and nested loop for each hour (0-59) and then get the folder content via the glob function and then save them all in an array, sort it and find the latest. Then delete the files, though this is even trickier because PHP cannot delete a folder unless it is empty, so you would need to delete the individual files, then delete the "minute" folder, once it is empty, delete the "hour" folder

Thanks Jachym. If the files can't be deleted automatically that's okay. I could delete them manually every week.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: SteveFitz1 on November 13, 2017, 04:59:15 PM
Thanks Steve. The camera is in a remote location that won't allow for a windows box unfortunately.

It doesn't have to be Windows. You would simply need to write a small script that used CURL (available on multiple platforms) to get the current image and you can save it by any name. Within that same script you could FTP that image whose name you know directly to your host.

Steve
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: bchwdlks on November 13, 2017, 05:00:50 PM
Can you put another ip device at your remote location ? If so you have an easy fix:

  • put a raspberry pi on the remote network
  • collect the images from the camera on the raspberry
  • watch the image directory on the raspberry with inotifywait
  • when it sees a new image let the raspberry ftp it to your web server with any name that works

Thanks bch. I was hoping I wouldn't have to go out there. It's a long way. It's possible. I have an older Raspberry Pi lying around. Is there a tutorial that you know of that I can use?

tripper22

I do not have a tutorial but this script is what I am using in a similar situation. Every 4th file added to the /home/pi/ButterflyCam directory causes a buzzer to sound. In your situation I believe you could do a 'mv $file NEWNAME' and follow that with a ftp to the server that you want the file to go to.

        inotifywait -m -e CLOSE_WRITE /home/pi/ButterflyCam/ | while read path action file
          do
                        echo "'$file' @ [`date +%Y/%m/%d\ %H:%M:%S`]"
                        case $PLAY in
                        4 )

                                SOUND=/home/pi/Music/buzzthruloud.wav
                                echo "$SOUND"
                                aplay $SOUND

                                PLAY=1
                                ;;
                        * )
                                echo "NO SOUND"
                                PLAY=`expr ${PLAY} + 1`
                                ;;
                        esac
          done
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 05:17:34 PM
Thanks Steve. The camera is in a remote location that won't allow for a windows box unfortunately.

It doesn't have to be Windows. You would simply need to write a small script that used CURL (available on multiple platforms) to get the current image and you can save it by any name. Within that same script you could FTP that image whose name you know directly to your host.

Steve

I guess it could be done with a Raspberry Pi like bchwdlks suggested. I would have to get the Raspberry Pi to capture an image with a static filename every x minutes then upload it to the server every 10 minutes. I have to admit I was hoping for something easier lol.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 05:37:32 PM
Theoretically.... but I cant really tell because I dont know the exact structure of your server

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         if(file_exists("/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("/webcam/image.jpg", file_get_contents($images[0]));



This should theoretically find the latest image and save it in webcam as "image.jpg", but I have no way to test this. Also I have no idea if the day and month in the date uses leading zero, which is crucial
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 06:03:11 PM
Theoretically.... but I cant really tell because I dont know the exact structure of your server

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         if(file_exists("/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("/webcam/image.jpg", file_get_contents($images[0]));



This should theoretically find the latest image and save it in webcam as "image.jpg", but I have no way to test this. Also I have no idea if the day and month in the date uses leading zero, which is crucial

Thanks very much Jachym. I am happy to test it. What needs to be done so that I can upload and run it?
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 06:18:18 PM
Theoretically.... but I cant really tell because I dont know the exact structure of your server

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         if(file_exists("/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("/webcam/image.jpg", file_get_contents($images[0]));



This should theoretically find the latest image and save it in webcam as "image.jpg", but I have no way to test this. Also I have no idea if the day and month in the date uses leading zero, which is crucial

Thanks very much Jachym. I am happy to test it. What needs to be done so that I can upload and run it?

I think I figured it out. I placed it in the webcam folder. This is what I get

Warning: file_get_contents(): Filename cannot be empty in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12

Warning: file_put_contents(/webcam/image.jpg): failed to open stream: No such file or directory in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 06:20:59 PM
OK, that means it did not find any images, which would suggest the path is incorrect, this could be for example down to the leading zeros, because "01" and "1" makes a difference
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 06:26:42 PM
OK, that means it did not find any images, which would suggest the path is incorrect, this could be for example down to the leading zeros, because "01" and "1" makes a difference

My root folder is the webcam folder. The AMC000X5_3R286G folder is the only folder in there with the file structure we discussed earlier if that helps you.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 06:37:06 PM
OK, that means it did not find any images, which would suggest the path is incorrect, this could be for example down to the leading zeros, because "01" and "1" makes a difference

My root folder is the webcam folder. The AMC000X5_3R286G folder is the only folder in there with the file structure we discussed earlier if that helps you.

I changed where to look for the folder and where to write the image.jpg. When it's run an empty image.jpg file is created in the root of webcam and I get the following error.

Warning: file_get_contents(): Filename cannot be empty in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12

With my changes:

Code: [Select]
<?php
$images 
= array();
for(
$i=0;$i<24;$i++){
    for(
$j=0;$j<60;$j++){
         if(
file_exists("./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               
$images[] = "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("./image.jpg"file_get_contents($images[0]));
?>
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 06:44:24 PM
Yes, still the same problem it didnt find any image in the folders, so there is some problem in the path to the files, as I said, it could be leading zeros or the name of the file is a bit different. You could add an echo there that would show you the image it is looking for

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         echo "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg<br>";
         if(file_exists("./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 07:15:12 PM
Yes, still the same problem it didnt find any image in the folders, so there is some problem in the path to the files, as I said, it could be leading zeros or the name of the file is a bit different. You could add an echo there that would show you the image it is looking for

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         echo "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg<br>";
         if(file_exists("./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

Bad news. The file name has changed so I changed it in the script 02[R][0@0][0].jpg So the file name will change. If there was a way to just grab the newest jpg though...

This what I get:

./AMC000X5_3R286G/2017-11-13/001/jpg/0/0/02[R][0@0][0].jpg
./AMC000X5_3R286G/2017-11-13/001/jpg/0/1/02[R][0@0][0].jpg
./AMC000X5_3R286G/2017-11-13/001/jpg/0/2/02[R][0@0][0].jpg
./AMC000X5_3R286G/2017-11-13/001/jpg/0/3/02[R][0@0][0].jpg
Etc.

I changed the script to reflect the filename change and I still get this error.

Warning: file_get_contents(): Filename cannot be empty in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12

I really appreciate all of your help Jachym but maybe this is getting to be a bit ridiculous.  ](*,)
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: Jáchym on November 13, 2017, 07:30:38 PM
Right, well Im afraid if even this already complicated file name is not final, there is not much you can do, the naming of the file by your webcam is almost unbelievable, I mean 01[R][0@0][0].jpg   ](*,)
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 13, 2017, 07:34:16 PM
Right, well Im afraid if even this already complicated file name is not final, there is not much you can do, the naming of the file by your webcam is almost unbelievable, I mean 01[R][0@0][0].jpg   ](*,)

Well I thank you very sincerely for all of your time and effort. I give up. I'm going to purchase another camera. Does anyone have any recommendations?
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 14, 2017, 12:04:02 AM
Can you pull a image directly from the camera:
http://[ip]/cgi-bin/snapshot.cgi?loginuse=[USERNAME]&loginpas=[PASSWORD]

Remove [] and insert info.

?

Hey droid. I was able to capture a snapshot of the image using the information you provided above.

I have decided to continue with this adventure after doing some more research and it appears that a Raspberry Pi will be the best solution. I was able to borrow the exact same camera for testing. I have an RP3 ready to go. I have some basic knowledge of how the Raspberry Pi's work and how to install software. But obviously nothing about scripts lol.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 14, 2017, 12:10:41 AM
Can you put another ip device at your remote location ? If so you have an easy fix:

  • put a raspberry pi on the remote network
  • collect the images from the camera on the raspberry
  • watch the image directory on the raspberry with inotifywait
  • when it sees a new image let the raspberry ftp it to your web server with any name that works

Thanks bch. I was hoping I wouldn't have to go out there. It's a long way. It's possible. I have an older Raspberry Pi lying around. Is there a tutorial that you know of that I can use?

tripper22

I do not have a tutorial but this script is what I am using in a similar situation. Every 4th file added to the /home/pi/ButterflyCam directory causes a buzzer to sound. In your situation I believe you could do a 'mv $file NEWNAME' and follow that with a ftp to the server that you want the file to go to.

        inotifywait -m -e CLOSE_WRITE /home/pi/ButterflyCam/ | while read path action file
          do
                        echo "'$file' @ [`date +%Y/%m/%d\ %H:%M:%S`]"
                        case $PLAY in
                        4 )

                                SOUND=/home/pi/Music/buzzthruloud.wav
                                echo "$SOUND"
                                aplay $SOUND

                                PLAY=1
                                ;;
                        * )
                                echo "NO SOUND"
                                PLAY=`expr ${PLAY} + 1`
                                ;;
                        esac
          done

Bch I have decided to go the Raspberry Pi route. I have a borrowed camera and everything I need to build and test it at home before driving out and installing it. Thanks.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 14, 2017, 03:32:32 AM

Hey droid. I was able to capture a snapshot of the image using the information you provided above.


Ok, can you post the url (hide the sensitive data)? It needs to end with .jpg or .png

Maybe you can get the image by the url and save it with another filename, using PHP, something like this:

<?php

  $input = 'http://www.ip.com/.xx.png';
  $output = 'image.jpg';

  if (file_put_contents($output, file_get_contents($input))) {

    echo " Get Succes $output";

  }

?>

Regards
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 14, 2017, 01:51:25 PM

Hey droid. I was able to capture a snapshot of the image using the information you provided above.


Ok, can you post the url (hide the sensitive data)? It needs to end with .jpg or .png

Maybe you can get the image by the url and save it with another filename, using PHP, something like this:

<?php

  $input = 'http://www.ip.com/.xx.png';
  $output = 'image.jpg';

  if (file_put_contents($output, file_get_contents($input))) {

    echo " Get Succes $output";

  }

?>

Regards

Thanks for the help droid. How do I do this test with a windows machine?
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 14, 2017, 02:17:22 PM
Can you post the url (hide the sensitive data)? It needs to end with .jpg or .png

Regards
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: tripper22 on November 14, 2017, 02:25:42 PM
It's an internal ip. I'm testing this at home with a borrowed camera. Sorry I guess i'm not understanding you.
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: droiddk on November 14, 2017, 02:27:01 PM
Ok. Then it wont work. Has to be able to show image from there camera you want to show image from.

Regards
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: nikosa69 on July 10, 2022, 03:31:03 AM
Good morning to everyone.
i am facing the same problem can anyone help me.
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/12.03[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/13.03[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/14.03[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/15.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/16.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/17.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/18.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/19.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/20.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/21.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/22.02[R][0@0][0].jpg
/public_html/import/lias2/Lias2/2022-07-10/001/jpg/09/23.02[R][0@0][0].jpg

how can i get the last image sent by my camera..
I tried with this but it gives me an error that it can't find the image.
the problem is in the image file 23.02[R][0@0][0].jpg which keeps changing in front of [R][0@0][0].jpg minutes seconds

<?php
$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         if(file_exists("/home/cams/public_html/import/lias2/Lias2/".date("Y-m-d")."/001/jpg/".$i."/[R][0@0][0].jpg")){
               $images[] = "/home/cams/public_html/import/lias2/Lias2/".date("Y-m-d")."/001/jpg/".$i."/[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("./image.jpg", file_get_contents($images[0]));
?>

If anyone can help, thank you very much....
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: davidefa on July 10, 2022, 06:55:03 AM
I would go for a get-last-jpg-file approach ( independently from the directory structure ).
- set $rootDir to your initial directory ( something like: /home/cams/public_html/import/lias2 in the example you posted )
- in $lastFile you should get the last jpg file name ( you should rename, copy... )

P.S.
Forgot to add that this is only half of the story as you should also delete old files/directories ( after a predefined 'grace time' ) otherwise you'll end up 'eating' all your hosting space
Title: Re: Amcrest camera image rename and move php script? Help please.
Post by: nikosa69 on July 14, 2022, 02:39:59 AM
good morning after a few tries i found the way to take the last picture.
I'm listing it here in case anyone needs it

/home/cams/public_html/import/lias2/Lias2/".date("Y-m-d")."/001/jpg/".sprintf('%02d', $i)."/".sprintf('%02d', $j).".".sprintf('%02d', $k)."[R][0@0][0].jpg