Friday, February 11, 2011

Jquery Uploadify: Rename Uploaded File

I have been searching for two days to find a solution which will let me upload employee image and rename it, I couldn't find any. Turns out it's pretty simple, I have to just pass the filename as query string and do a little modification in uploadify.php file.
  1. Passing the filename as part of the query string - followed by '?' mark include the filename with the paramater 'script'
    'script' : 'uploadify/uploadify.php?name=imagename'
    //don't worry about the extension
  2. Modify the following line
    $targetFile =  str_replace('//','/',$targetPath) . 
    $_FILES['Filedata']['name'];

    with this
    if(isset($_GET['name'])){
    $targetFile =  str_replace('//','/',$targetPath) . $_GET['name']. 
            substr($_FILES['Filedata']['name'],-4);
     } else{
        $targetFile =  str_replace('//','/',$targetPath) .
          $_FILES['Filedata']['name'];
     }
I hope this is helpful