SDK |
Documentation |
JavaSonics ListenUp is no longer for sale.Writing Server Scripts in PHPPHP has a simple utility for receiving uploaded files. Documentation is here: http://www.php.net/manual/en/features.file-upload.php. For a complete PHP example used with ListenUp, please see the file "php_test/handle_upload_simple.php". Note that this file checks for specific file names that we use in our tests. You should modify or remove these checks to match your application's file names. Use Plain TextThe first thing you must do in your PHP script is to set the content type to plain text. This simplifies the text that is sent back to ListenUp, making it easier to parse. These header values must be set before you send any other text! header("Cache-control: private"); header("Content-Type: text/plain"); Getting Variable Data (Name/Value pairs)We use the $_POST global to access the posted variables. This technique will work regardless of the value of the register_globals variable and is thus very portable. We use strip_tags() to prevent pirates from hacking your server scripts. For example, to get the duration of the uploaded file in seconds: $duration = strip_tags($_POST['duration']); Getting the Uploaded FilePHP stores POSTed files in a temporary area, then fills in the array $_FILES with the information you need. Here is how to get the file information. Note we use the name 'userfile' because that is what ListenUp called the file. // Get size of uploaded file. $upfile_size = $_FILES['userfile']['size']; // Get suggested name of file. $upfile_name = $_FILES['userfile']['name']; ValidationIt is possible that someone could create another program that pretended to be ListenUp and send you some bogus files. So you should check to make sure that noone is uploading a file that is too big. if( $upfile_size > $upfile_size_limit) { echo "ERROR - file too large, $upfile_size > $upfile_size_limit\n"; } Also make sure that noone is sending a tricky file name by stripping off path information. $upfile_name_safe = basename($upfile_name); Copy File to DestinationCopy file from temporary PHP area to its final location. PHP must have permission to write to that area. $uploads_dir = "../../uploads/"; move_uploaded_file($_FILES['userfile']['tmp_name'], $uploads_dir . $upfile_name_safe ); Problems with Large FilesYou may have problems uploading large files. Here are some things to consider:
Return Status CodesYour script must return a status code of SUCCESS, WARNING or ERROR at the beginning of a line. For example: echo "SUCCESS - file uploaded.\n"; |