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
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.
Reset the _FILES array, and store the first element in the variable temp.
Ensure the variable refers to a successfully uploaded file, and then save it to the folder set in step 1.
If the variable is not an uploaded file, return as 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/.
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
- Open your configuration file in any text editor (e.g. Notepad on Windows).
Only a portion of the full <mediaSettings> element is shown here.