Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is it possible to BACKUP old versions of uploaded (overwritten) files in the server?

    For example in my web server, there are 4 webcam images in one folder (continiously updated by overwriting according

    to the upload coming from webcam software - as "a.jpg, b.jpg, c.jpg, d.jpg)



    Webcam software is always overwriting the image files but I want to keep and save all uploaded images

    with increasing numbered file names

    (as a0001.jpg, a0002.jpg, a0003.jpg, .... b0001.jpg, b0002.jpg, b0003.jpg, .... for every webcam image

    file)

    in a seperate folder (by using php or cron job?) while keeping their upload date and time information.



    I dont have knowledge in scripting language , but I can guess that there may be some way to do it by PHP or CRON JOB?
    Last edited by damlays; 11-14-2012 at 05:15 AM.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    you could set a cron job to do that for you, PHP might be something like ...

    cron /usr/bin/php -q /path/to/script.php
    PHP Code:
    <?php
    $src_folder
    ='/home/blah/webcam';
    $dest_folder='/home/blah/webcam/history';
    $arr=array('a','b','c','d');
    foreach(
    $arr as $a){
     if(
    file_exists("$src_folder/{$a}.jpg")){
        
    rename("$src_folder/{$a}.jpg","$dest_folder/{$a}_".date('ymdhis').".jpg");
     }
    }
    ?>
    you could do the same with bash on linux of course rather than calling php, whichever you are more comfortable with
    Last edited by firepages; 11-14-2012 at 08:18 AM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your help.

    When I tried to establish your solution I couldn't succeed and I thought that maybe cron job is not right way of doing this?

    Because in the host control panel, there is cron job function with the triggering according to time (minimum every minute is possble)

    But I need the file will be backed up triggered by every new upload.

    Is there any way doing this? (Or am I missing some points?)

  • #4
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    By the way now I tried the code without cron.. I made cam.php file and put to the same folder where image files sits;

    <?php
    $src_folder='/public_html/.mydomain/cam';
    $dest_folder='/public_html/.mydomain/cam/backup';
    $arr=array('cam_office1','cam_office2a','cam_office2b','cam_home');
    foreach($arr as $cam_office1){
    if(file_exists("$src_folder/{$cam_office1}.jpg")){
    rename("$src_folder/{$cam_office1}.jpg","$dest_folder/{$cam_office1}_".date('ymdhis').".jpg");
    }
    }
    ?>

    I've created the folder "backup"

    After that from web browser I open http://example.com/cam/cam.php

    This must write images files to "backup" folder, is it right?
    Nothing is written to the new folder?
    Last edited by damlays; 11-14-2012 at 01:43 PM.

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    the folder needs to we writable by the web-server ... this will check...
    PHP Code:
    <?php
    $src_folder
    ='/public_html/.mydomain/cam';
    $dest_folder='/public_html/.mydomain/cam/backup';
    $arr=array('cam_office1','cam_office2a','cam_office2b','cam_home');
    if(!
    is_writable($dest_folder)){
        die(
    "$dest_folder not writable");
    }
    if(
    file_exists("$src_folder/{$cam_office1}.jpg")){
        
    rename("$src_folder/{$cam_office1}.jpg","$dest_folder/{$cam_office1}_".date('ymdhis').".jpg");
    }else{
       echo 
    "can't find file {$src_folder}/{$cam_office1}.jpg<br />";
    }
    ?>
    Last edited by firepages; 11-15-2012 at 12:52 AM.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Folder was not writeable but I could solve that problem...

    rename("$src_folder/{$cam_office1}.jpg","$dest_folder/{$cam_office1}_".date('ymdhis').".jpg");
    is MOVING the file to the destination folder,

    Is there any other command instead this, which can "COPY" the file with renaming, but without touching the file sitting in the original location?

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    OK, change rename() to copy()
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much....now we have a php file which makes the copy of all images..this was a great help for me..


    If I am not taking your time much, I want to ask your idea about the unsolved part of the solution as well..
    Now I am triggering this php file manually by browser or I can make a cron job for every minute..


    But both of them are not good solutions, because
    1)If there is no change (new upload according to the dedected motion) in camera image file, it is useless to save a copy of image in every minute
    2)And also, in one minute there can be 10 different uploads but I can catch and copy only 1 image in this time period by this way

    So is there any other ways possible to run this php triggered by every new uploads, or is it impossible to do that?

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    Quote Originally Posted by damlays View Post
    So is there any other ways possible to run this php triggered by every new uploads, or is it impossible to do that?
    not impossible but would require root access to your server & it ain't straight-forward, it requires inotify-tools on linux so perhaps google for that if you are feeling brave

    The obvious alternative is CRON, add to your crontab ... check the php path with `which php`
    /usr/bin/php -q /full/path/to/yourscript.php

    I am not sure how your images get put on the server, perhpas your cameras have some notify action ? possibly they can send an email or call a webpage when they save the image... need more info there though.

    as for not saving the same image file several times you could use md5_file() to generate a hash of the last image moved, save that somewhere (db or text-file) then check the md5() of the image to make sure it has changed b4 you do your next move?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #10
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I see. For entering inotify-tools on linux I don't think so I am brave enough

    About md5_file() , I think I understand your point, php file will check this information every time before saving a new file and if it is the same file it will not save..right?
    I can guess that it is easy script for you, but it seems a little bit advanced programming for me
    I am using iSpy security software for uploading image files, uploads on motion detection, but I couldn't find sending email or caling a web page function paralel with upload..

    But I can ask an easier script help from you maybe be the solution of this problem.
    If we can modify the current code for saving the image files every hour to a new created folder instead of one stable folder, then it can be possble to manage many saved files.

    I mean for every day one parent folder of the day will be created automaticly by php file if it is the first file saving after 12:00 am of previous day. Folders as below
    121116
    121117
    121118
    .......

    And in each folder, 24 folders will be created one by one by php file when the time comes to save an image if file belongs to a new hour, as
    00
    01
    02
    04
    ....
    ...
    22
    23

    Is it an easy and short modification or difficult and long?
    Last edited by damlays; 11-16-2012 at 08:54 AM.

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,344
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by damlays View Post
    But I need the file will be backed up triggered by every new upload.
    How is the file uploaded? - FTP or a HTTP upload?

    If its FTP then the most you're going to get is a cycling script that cycles for say 59 seconds before quitting and being restarted by a cron.

    If you have total control of the system and can run scripts indefinitely then you could write a service that will just run continually checking for new files and saving them otherwise you're stuck with the 59 seconds and a new cron instance scenario.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #12
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    How is the file uploaded? - FTP or a HTTP upload?

    If its FTP then the most you're going to get is a cycling script that cycles for say 59 seconds before quitting and being restarted by a cron.
    .
    Software is uploading with ftp. And I dont have the full control of the system.
    But what is cycling here, can you explain that some more?

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,344
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Cycling = looping.

    Most servers have a php script maximum execution time of either 30 or 60 seconds. Now if you have a 60 second max then you could easily loop a script for 59 seconds (with a sleep between each loop to stop your host shutting you down for CPU hogging). That means that every time the script loops it will check for any files in directory A and copy them into directory B with a new name.

    On the 60th second your cron triggers a new version of the script to run and the whole process starts again for another 59 seconds.

    If you're unsure of how to set this up, I can do the initial checks of your environment for you (checking max exec time etc) to see if its suitable but if you want the code written by me it would be chargeable.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #14
    New Coder
    Join Date
    Nov 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I understand.

    If that code is that much complex to be chargable I will not try that way. Because this thing which I am trying is a completely amateur effort for me, and the purpose of posting in this forum is for seeking some simple and amateur helps only. Thank you.

    In any way, I wonder about is it possible that php script can understand a new file is uploaded while looping? Is it about using the same technique related with md5_file() which "firepages" told in previous posts?

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,344
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by damlays View Post
    If that code is that much complex to be chargable I will not try that way. Because this thing which I am trying is a completely amateur effort for me, and the purpose of posting in this forum is for seeking some simple and amateur helps only. Thank you.
    Don't be put off. It isn't overly complex so it's within your grasp, I was just offering to get you up and running asap for a fee (I've been out of work for 2 years so can't blame me for tryin eh?).

    Quote Originally Posted by damlays View Post
    In any way, I wonder about is it possible that php script can understand a new file is uploaded while looping? Is it about using the same technique related with md5_file() which "firepages" told in previous posts?
    Yes. It would be able to recognise a different file to the last one by checking the MD5 as firepages suggests. An MD5 checksum is basically a 32bit string comprising of letters and numbers which is basically generated through voodoo and creates a digital fingerprint of a file. It's extremely rare for two files to ever share the same MD5 so that is how you could determine if the file is the same or different to the last one moved. Either way, assuming you're moving the file from A=>B then it would no longer be at the source anyway so ths script would just look for new files and move them.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •