JavaSonics

SDK

Documentation


Web Home

SDK Home

Docs

Test PHP

Test ASP

Test ASP.NET

Examples

Demos

Download

Purchase

Support

Forum

Login

Contact Us

Company


JavaSonics ListenUp is no longer for sale.

Writing Server Scripts in PHP

PHP 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 Text

The 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 File

PHP 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'];

Validation

It 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 Destination

Copy 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 Files

You may have problems uploading large files. Here are some things to consider:

  1. If you based your PHP code on our example then you may have inherited our safety limit. Look for a variable like "upfile_size_limit" in the PHP script and increase the limit.
  2. Your PHP may be configured with a low limit on the size of an HTTP PHP request. Take a look in your "/etc/httpd/conf.d/php.conf" file. The variable LimitRequestSize can be bumped up if needed. Don't forget to restart Apache if needed. Look for a comment posted 04-Dec-2002 on this page for more on this topic.
  3. There are a few configuration variables that affect uploaded file sizes. They are set in the "php.ini" file. Their values can be printed in your PHP script.

    echo "post_max_size = " . ini_get("post_max_size") . "\n";
    echo "upload_max_filesize = " . ini_get("upload_max_filesize") . "\n";
    echo "max_input_time = " . ini_get("max_input_time") . "\n";

Return Status Codes

Your script must return a status code of SUCCESS, WARNING or ERROR at the beginning of a line. For example:

     echo "SUCCESS - file uploaded.\n"; 

[Top] [Previous] [Next]


© 2001-2006 Mobileer, Inc.   This page is from the ListenUp SDK. You can download the SDK from here.