Support » Plugin: React Webcam » Overwrite time stamped image?

  • Resolved smac2

    (@smac2)


    Hello,
    Is it possible to overwrite the same timestamped image in the wp-content/uploads/webcam folder? So the image name, which is in this format: yy-mm-dd.jpg, stays the same but the image itself is different.

    Because otherwise, that folder will fill up with hundreds of images very quickly.

    Thank you!
    S

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Radek Matej

    (@nikdo)

    Hi,

    It’s not possible. The plugin depends on correctly timestamped images and doesn’t have any clean up functionality. It just reads images in a folder.

    You have to implement your own script that will us WP cron to periodically delete old files in that folder. Or you can use some plugin that can do that. Quick search led me to this: https://wordpress.org/plugins/bulk-delete/

    Radek

    Ok, thanks Radek!

    In cpanel you could just implement a cronjob:
    find /home/...servername/public_html/domain/wp-content/uploads/webcam -type f -mmin +28 -delete

    Plugin Author Radek Matej

    (@nikdo)

    Good tip. Thanks for sharing!

    Hi

    I fixed with problem with a small change – see the unlink loop below. Hope that helps!

    Peter

    // Returns filename of the last webcam image.
    function get_last_filename($subdir) {

    $upload_dir = wp_upload_dir();
    $webcam_dir = $upload_dir[‘basedir’] . ‘/’ . WEBCAM_DIR . ‘/’;

    if ($subdir && preg_match(‘/[a-z0-9]/i’, $subdir)) {
    $webcam_dir .= $subdir . ‘/’;
    }

    foreach (array_filter(glob($webcam_dir . ‘*’), ‘is_file’) as $path) {
    $last_filename = basename($path);
    }
    // Added code: Unlink all but latest image
    foreach (array_filter(glob($webcam_dir . ‘*’), ‘is_file’) as $path) {
    if ($last_filename <> basename($path)){
    unlink($path);
    }
    }
    // … end of added code
    return $last_filename;

    };

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Overwrite time stamped image?’ is closed to new replies.