Support » Fixing WordPress » Migrating to WordPress

  • I am relatively new to WordPress and am in the process of changing several sites over from to this platform. One site I have uses a bit of code in in my current index.php to control uploaded images from my webcam. I am not sure where to place this code in the WordPress structure.

    The webcam uploads a photo every 30 seconds and each photo has a time stamp so this code is used to delete older photos and rename the most recent photo so the website can display the most up to date image. I image a plugin would be best bet, but haven’t found one so need to find how and where to insert this code.

    the code in question in index.php is:

    <!-- PHP to fix web cam images -->
    // Run from on directory above your FI... directory
    // Change the next line for your snap directory
    chdir ('webcamsandlinks/images/FI9900P_00626E6A54A2/snap'); 
    $files = glob('*.jpg'); 
    // Exit if there is not a new snapshot file
    if(count($files) < 1){ 
       return 0;
    // Grab the first file and timestamp
    $file = array_shift( $files);
    $mTime = filemtime( $file);
    // Check the other files and delete if older
    foreach($files as $currFile){ 
      $currTime = filemtime($currFile);
      if( $currTime > $mTime){ 
        $file = $currFile;  
        $mTime = $currTime;
     } else {unlink($currFile); }
    // Only the newest file remains
    // Rename the snapshot file using the first 8 chars
    rename($file, substr($file, 0, 8) . '.jpg'); 
    <!-- End PHP -->
Viewing 2 replies - 1 through 2 (of 2 total)
  • This sounds like something that the code that uploads the image should do. If you want it to run every 30 seconds, or any time schedule, you could try to attach it to WP’s chron, but it won’t work well. You could put it on your server’s chron, if you have access to that.
    One caution is to not post code on the forum that hackers would want to see, because there could be a way to exploit it that you are unaware of. Now the name of your snap folder is published, and the fact that you are using a wildcard with glob and unlink, which was the subject of a security update very recently.

    Thread Starter alwiggins


    Thanks Joy,
    I appreciate the cautionary statement, thanks.
    What method do most sites use to add auto updating web cam images to a wordpress site?
    There don’t appear to be any plugins that are widely used and rated to accomplish this task.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Migrating to WordPress’ is closed to new replies.