SDK |
Documentation |
JavaSonics ListenUp is no longer for sale.Naming Files on the ServerPeople often ask us how to name the audio files on the server. The file name is ultimately decided by the script that you write on your server. Your script writes the file to disk. You have complete flexibility in naming those files. Suggesting File Names from the ClientThe client computer can send suggested names along with the uploaded file. There are two ways to specify this name. 1) Suggest a name using the "uploadFileName" Applet parameter. 2) Use JavaScript to upload the message and pass a file name. Details here. document.ListenUpRecorder.sendRecordedMessage( uploadFileName ) Generating File Names on the ServerWhen you receive a name from the client computer you should strip it down to prevent a hacker from uploading commands or pathnames to your server. This example shows how to do this in PHP. In all these examples we are writing to a folder called "uploads" but you can use any folder to store them. Note that you may need to change the permission of the folder so that PHP can write to it. $raw_name = $_FILES['userfile']['name']; // Strip path to prevent uploads outside target directory. $actual_file_name = "uploads/" . basename($raw_name); You may want to put the time in seconds that the file was uploaded into the name. Note that if two people upload a file in the same second then they will get the same file name. So you may want to also include the user name. In this example we use a ".wav" suffix for normal WAV files. If you uploaded Speex files then use the ".spx" suffix. $actual_file_name = "uploads/msg_" . $user_name . "_" . time() . ".wav"; Or you can use a cryptic but unique name based on MD5. $actual_file_name = "uploads/msg_" . md5(uniqid(rand(),TRUE)) . ".wav"; The most reliable way to get a unique name is to use auto-incremented SQL database record IDs as part of the name. That is beyond the scope of this document. Once you have a name you can move the audio recording from temporary storage to its final place. move_uploaded_file($_FILES['userfile']['tmp_name'], $actual_file_name ); |