Hi Guys

Sometime might be same to me you need that uploaded file name must be unquie or untamper so that you can use this snip code to resolve your issue.


function vv_video_file_conflict_file_insert($file) {
  // Here in split file uri into chuncks because i want to implement this code
  // for specific directory of the files 
  //  public://videos/original/job/---here-are-my-files
  $expload = explode('/', $file->uri);
  if($expload['2'] == 'videos' && $expload['3'] == 'original' && $expload['4'] == 'job'  ) {
    $newuri = vv_video_file_conflict_rename_with_unique($file->uri);
    file_move( $file, $newuri, FILE_EXISTS_REPLACE);
    $file->filename = $name;
  }
}

function vv_video_file_conflict_rename_with_unique($uri) {
     $expload = explode('/', $uri);
     $fname = end($expload);
     $without_ext = preg_replace('/\.[a-z0-9]+$/', '', $fname);
     if(preg_match('/\.[a-z0-9]+$/', $fname, $match)) {
       $new_name = $without_ext.uniqid('_unique_id_').'_'.mt_rand();
       $expload[count($expload) - 1] = $new_name.$match[0];
       $newuri = join( '/', $expload);
       return $newuri;
     }
  
}

Supposed you uploads a file with name test.flv then code rename its uri to something like this test_unique_id_525795a9144a5_1308199621.flv.
without code: public://videos/original/job/test.flv
with code: public://videos/original/job/test_unique_id_525795a9144a5_1308199621.flv