I am renaming the uploaded file in a PHP script that handles the upload. The original filename is returning via “file.name” in the upload_success_handler, not the new filename. Any idea how to have it return the new name? Thanks!
Renaming Uploaded File
February 28, 2009 - 12:28pm
February 28, 2009 - 12:33pm
if (!move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
HandleError("File could not be saved.");
exit(0);
}
this is one of the last lines in upload.php
here is the function http://nl3.php.net/move_uploaded_file used
just edit the 2d parameter of the function to change the path and name.
ps: if you only want to change the file name change the $file_name only
February 28, 2009 - 12:41pm
Thanks Traxion. I've actually got that part working, but the new filename isn't returning via the uploadSuccess handler's file object's name property. The original name is returning, not the new name.
February 28, 2009 - 9:52pm
There is a parameter passed to the success handler called server_data. If you pass information back from your script with say <?php echo $new_file_name ?> you can use server_data to get that info back.
So a good example is in the uploadSuccess handler alert(server_data) which is the second parameter. And in your upload.php file just echo 'test'
Take a look at the server_data part in the documentation
http://demo.swfupload.org/Documentation/
Also for a more complex example take a look at the ApplicationDemo in the demos files.