0

I am using uploadifive to upload files on to my server. But before the files are moved to the permanent folder (eg. move_uploaded_file($tempFile, $targetFile)) they are renamed.

In the past I used uplodify and I user to be able to return the new file name like so

'onUploadSuccess' : function(file, data, response) {
        alert('Renamed file name is - ' + data);
    }

Unfortunately the onUploadSuccess method is not available for uplodifive.

How can I return to the client the new filename?

here is the code I use to rename and upload the file

if (!empty($_FILES) ) {
    //arrayDump($_FILES);
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath =  ROOT_FIXED . UPLOAD_DIR . $targetFolder;   //$_SERVER['DOCUMENT_ROOT']
    $new_filename = USER_ID . '-' . time() . '-' . alphanumeric($_FILES['Filedata']['name']);
    $targetFile = rtrim($targetPath, '/') . '/' . $new_filename;
    $fileParts = pathinfo($new_filename); 

    if (in_array(strtolower($fileParts['extension']),$fileTypes) && $_FILES['Filedata']['size'] <= $max_size ) {
        if(move_uploaded_file($tempFile, $targetFile))
            echo $new_filename;
        else
            echo 'INVALID';
    } else 
        echo 'INVALID';

} else 
        echo 'INVALID';


function alphanumeric( $string ){
    return preg_replace('/[^a-zA-Z0-9\.\_\-]/', '', $string);
}

Thanks

danmullen
  • 2,556
  • 3
  • 20
  • 28
Jaylen
  • 39,043
  • 40
  • 128
  • 221

1 Answers1

0

I figured it out finally

'onUploadComplete' : function(file, data){
// this will print the new file name
console.log($.trim(data));
}
Jaylen
  • 39,043
  • 40
  • 128
  • 221