Page tree
Skip to end of metadata
Go to start of metadata

This article provides a sample script, written using PHP, to upload images via the HTTP POST method. Instructions on how it can be tailored for use in your Web applications are also included. You will need to set this facility if you would like to be able to upload local images to the server.

Download the PHP multimedia upload example code: php_postacceptor.php.
The source for EditLive multimedia upload scripts can also be found in the SDK_INSTALL/webfolder/uploadscripts/ directory where SDK_INSTALL represents the directory to where the EditLive! SDK is installed.

Defining the Location of the Image Upload Handler Script

The location of the image upload handler script must be defined within the EditLive! configuration file. This setting is configured via the href attribute of the <httpUpload> element of the configuration file. To use this example script, the href attribute should point to the location of this script on the server.

Defining the Location of the Image Upload Directory

This example script uploads images to the directory specified by the imageFolder variable. In order for images to function correctly within EditLive!, the base attribute of the <httpUpload> element must reflect the location of the directory where images are located on the Web server.

Creating an Image Upload Handler Script

  1. Create a variable to store the location of the images on the server. In this example, we are using the images subfolder of the script location.

     
    <?
       /*********************************************
        * Change this line to set the upload folder *
        *********************************************/
       $imageFolder = "images/";
  2. Reset the _FILES array, and store the first element in the variable temp.

       reset ($_FILES);
       $temp = current($_FILES);
  3. Ensure the variable refers to a successfully uploaded file, and then save it to the folder set in step 1.

     
      if (is_uploaded_file($temp['tmp_name'])){
        $filetowrite = $imageFolder . $temp['name'];
        move_uploaded_file($temp['tmp_name'], $filetowrite);
  4. If the variable is not an uploaded file, return as error.

     
      } else { 
         // Notify EditLive! that the upload failed
         header("HTTP/1.0 500 Server Error");
      }
    ?>

Example Image Upload Handler Script

Tiny has written a sample image upload handler script using PHP. This script can be found at SDK_INSTALL\webfolder\uploadscripts\php\php_postacceptor.php, where SDK_INSTALL represents the location where the EditLive! SDK is installed.

For image upload, one line of code in the php_postacceptor.php file must be changed. This line of code specifies the location where you wish image files to be uploaded to. If the location of the upload acceptor script was http://www.yourserver.com/scripts/php_postacceptor.php then setting the imageDir variable to ../images would upload the images to a directory with the URL http://www.yourserver.com/images/.

$imageFolder = "images/";

Relative paths specified within the image upload acceptor script are relative to the Web accessible location of the image upload acceptor script.

Integrating the Upload Script

  1. Open your configuration file in any text editor (e.g. Notepad on Windows).
  2. Locate the <mediaSettings> element and add a <httpUpload> element to it.

    Only a portion of the full <mediaSettings> element is shown here.

     
    <mediaSettings>
       <httpUpload
          base="images/"
          href="php_postacceptor.php">
       </httpUpload>
       ...
    </mediaSettings>

See Also

  • No labels