LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

Get New Changed Name After Upload #164

Closed hezhez closed 8 years ago

hezhez commented 8 years ago

Hi,

I've wrote a addon code that manipulate with the uploaded file name (Make random name for each file on the uploader.php), how can i transfer it to client side ?

I've tried changing - $newFileName, but the the "filename response" i get the original file name.

How can i transfer the new name from the uploader.php to the frontend call back ?

Thanks !

LPology commented 8 years ago

Can you post your code?

hezhez commented 8 years ago

Thanks for the quick reply, sure -

Just before the end of uploader.php code - (Line 273) - $this->savedFile = $this->uploadDir . $this->fileName;

i've added this -

$photoFormat = substr($this->fileName, strrpos($this->fileName, '.')+1); $targetFile = rand_string(7,'') . '.' . $photoFormat;

(rand_string is the random function name)

and the new name($targetFile) i want to output in the response of "onComplete".

Thanks !

LPology commented 8 years ago

This needs to be done in your upload handler script, not in the FileUpload class in Uploader.php.

Can you post the code you're using to handle the file upload?

hezhez commented 8 years ago

Hi !

Got the problem solved, i'm outputting the new file in file_upload.php -

echo json_encode(array('success' => true, 'uploadedFile' => 'upload_files/'.$targetFile));`

Thanks for the kind help !