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