• Is it possible to insert a variable like %data% or %time% to make the filename unique and avoid duplicates? (for example for guests…)

Viewing 1 replies (of 1 total)
  • Plugin Author nickboss

    (@nickboss)

    Here is a hook that will append datetime (with microseconds) in the filename, so that you are sure that there will be no duplicates:

    if (!function_exists('wfu_before_file_check_handler')) {
    	function wfu_before_file_check_handler($changable_data, $additional_data) {
    		$path = wfu_basedir($changable_data["file_path"]);
    		$basename = wfu_basename($changable_data["file_path"]);
    		$filename = wfu_filename($basename);
    		$ext = wfu_fileext($basename, true);
    		$utim = microtime(true);
    		$tim = floor($utim);
    		$ms = round(($utim - $tim) * 1000000);
    		$datestr = date(preg_replace('<code>(?<!\\\\)u</code>', $ms, "YmdHisu"), $tim);
    		$changable_data["file_path"] = $path.$filename."-".$datestr.$ext;
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2); 
    }

    You need to add it in functions.php file of your theme.

    Of course there is another simpler option. Open the visual editor of the upload form, locate option Duplicates Policy and set it to maintain both. The uploaded file will be renamed, if necessary, in order to avoid conflicts with existing files.

    Regards

    Nickolas

Viewing 1 replies (of 1 total)
  • The topic ‘Video Filename webcam’ is closed to new replies.