When inserting and uploading local images and objects (multimedia files) to a remote server, Ephox EditLive! for XML uses the HTTP multipart form-data protocol.
The <httpUpload> element of the XML configuration file contains the configuration information for the HTTP Upload functionality for images and other multimedia objects.
Using the HTTP POST method to insert and upload images and objects offers a secure way of allowing end users to interact with the remote server that the images are to be stored on.
In order to upload local files to the remote server via HTTP, you will need a server-side upload handler script that accepts the images and objects on the server and stores them in the correct directory or database. This script is the same script that would be used for uploading any file to the server via the HTTP POST method. For example, when you use a file input element (i.e. <INPUT type="file">), the script specified in the ACTION attribute of the form element is used to upload the file to the server. This is the same script specified in EditLive! for XML to upload local files inserted into EditLive! for XML to the remote server.
The HTTP upload configuration requires a URL corresponding to the image upload handler script and also a base property to use with image and object URLs. These properties can be set via the href and base attributes of the <httpUpload> element respectively.
This setting defines the location on the Web server of the script which handles file uploads.
Relative URLs may be used. In this case the URL will be relative to the location of the page in which EditLive! for XML is embedded unless otherwise set via a base URL property.
You should enter in this field the absolute URL for where the files are to be uploaded. The files can then be found by directing your browser to the directory of the URL you supplied, after they have been uploaded.
Relative URLs may be used. In this case the URL should be relative to the page which will be used to display the finished documents. For the images or objects to be displayed correctly in the pages in which EditLive! for XML is embedded, the relative URL should also be the correct location relative to the pages in which EditLive! for XML is embedded.
Example 10.1. HTTP Upload Absolute BASE URL Configuration Example
In this example the location for the image upload script is http://www.yourserver.com/scripts/upload.jsp
The uploaded files can be found in a directory with the URL http://www.yourserver.com/userfiles/
<editLive>
...
<mediaSettings>
...
<httpUpload
base="http://www.yourserver.com/userfiles/"
href="http://www.yourserver.com/scripts/upload.jsp"
/>
...
</mediaSettings>
...
</editLive>Example 10.2. HTTP Upload Relative BASE URL Configuration Example
If the location of the display page directory is: http://yourserver.com/editlivejava/startcms/site
The location of the directory containing the pages with EditLive! for XML embedded in them is: http://yourserver.com/editlivejava/startcms/cms
Then the correct relative base URL setting for both the viewing and editing pages to function correctly with images and objects would be: ../site/objects
The upload handler script is located at http://yourserver.com/scripts/uploadhander.asp
We recommend using absolute URLs when possible, as it is less likely to lead to confusion.
<editLive>
...
<mediaSettings>
...
<httpUpload
base="../site/objects"
href="http://yourserver.com/scripts/uploadhandler.asp"
/>
...
</mediaSettings>
...
</editLive>Images and embedded object files are uploaded when the contents of Ephox EditLive! for XML are submitted. This occurs when the form which contains Ephox EditLive! for XML has its submit method called.
Local files which are uploaded to the server by EditLive! for XML are placed within a form field with the name image. When implementing an upload acceptor script specifically to receive files from EditLive! for XML the script should be made to accept files submitted within the image field.
It is possible to dynamically assign the URL for images or objects embedded within the content as they are uploaded. This functionality is achieved via the POST acceptor for files. If the POST acceptor returns a string containing a URL the URL is inserted into the document source code as the URL for the file. In this way it is possible to dynamically assign the directory files are uploaded to without having to dynamically generate the configuration file.
For this functionality to operate correctly the relevant upload acceptor script must only return a single line string with the URL corresponding to the location for the uploaded file.
When setting the file URL in this manner the URL returned by the POST acceptor script to EditLive! for XML takes precedence over the base setting in the XML configuration file.
The URL returned by the POST acceptor must be exactly the URL to be used for the relevant file in EditLive! for XML.
Ensure that the URL returned by the POST acceptor does not include a newline character. Note that newline characters can be introduced by using a method such as println or writeln. Ensure you are using methods which do not introduce a newline character such as print or write.
EditLive! for XML is packaged with sample upload scripts for ASP, JSP and ASP.NET that enable uploads for common image formats. The source for these scripts can be found in the SDK_INSTALL/webfolder/uploadscripts/ directory where SDK_INSTALL represents the directory to where the EditLive! for XML SDK is installed. The upload scripts can also be extended to be used with files associated with embedded objects (e.g. Macromedia Flash files). This is achieved by adding the relevant extensions to the list of known file types.
Documentation is also available for the upload acceptor scripts:
There are a number of problems that may occur while attempting to use HTTP Upload. These can be complicated and vary from server to server. For more information on the settings relevant for your server please consult the documentation for your server. Some common problems include:
Sever side settings - ensure that the HTTP upload script exists in a directory in which scripts can be executed.
File system permissions - ensure that the file permissions of the directory in which files are to be placed has write and read permissions set.
This article provides a sample script, written using Active Server Pages and VBScript, 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.
The location of the image upload handler script must be defined within the XML 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.
This example script uploads images to the directory specified by the imageDir variable. In order for images to function correctly within EditLive! for XML the base attribute of the <httpImageUpload> element must reflect the location of the directory where images on the Web server.
Ephox has written a sample image upload handler script using Active Server Pages and VBScript. This script can be found at SDK_INSTALL\webfolder\uploadscripts\asp\fileUpload.asp where SDK_INSTALL represents the location where the EditLive! for XML SDK is installed.
Below are the steps required to use the ASP image upload handler in your own Web application.
For image upload, one line of code in the fileUpload.asp 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/fileUpload.asp then setting the imageDir variable to ../images would upload the images to a directory with the URL http://www.yourserver.com/images/.
Dim imageDir imageDir="../images"
Relative paths specified within the image upload acceptor script are relative to the Web accessible location of the image upload acceptor script.
EditLive! for XML's configuration file should now be edited to reflect the changes made in the previous step. You will find these settings within the <httpImageUpload> element. The URL setting should reflect the location of the fileUpload.asp file on your Web server.
The following example reflects the setting of the href attribute of the <httpUpload> element if the upload script could be found at the URL http://www.yourserver.com/scripts/fileUpload.asp.
<editLive>
...
<mediaSettings>
<httpUpload
base= ...
href="http://www.yourserver.com/scripts/fileUpload.asp"
/>
...
</mediaSettings>
...
</editLive>Finally the HTTP Image Upload base attribute should be changed to reflect the location where images can be found on your Web server.
This location may not be the same value as that used within the upload acceptor script, above. Rather, it will be the virtual directory alias used by your Web server for the location listed in upload acceptor script.
This example follows from the code above. It uses an absolute URL as the value of the base attribute. The value of the base attribute corresponds to the URL that for the directory that images are uploaded to.
<editLive>
...
<mediaSettings>
<httpUpload
base="http://www.yourserver.com/images/"
href="http://www.yourserver.com/scripts/fileUpload.asp"
/>
...
</mediaSettings>
...
</editLive>The ASP upload acceptor script provided with EditLive! for XML can, by default, only be used with common image file types. This is restricted by inspecting the extension of an uploaded file. Support for other file types, including multimedia object types such as Macromedia Flash (.swf) and Apple QuickTime (.mov) can easily be added by adding the relevant extension to the list of allowed extensions in the upload acceptor script.
The list of permitted extensions can be found at the bottom of the ASP upload acceptor script file in the following statement:
if OnlyExtention="jpeg" or _
OnlyExtention="jpg" or _
OnlyExtention="tiff" or _
OnlyExtention="png" or _
OnlyExtention="gif" then
call SaveFile(curDir & "\" & OnlyFileName, FileData)
end ifThe example below demonstrates how this example can be extended to handle Flash and QuickTime files:
if OnlyExtention="jpeg" or _
OnlyExtention="jpg" or _
OnlyExtention="tiff" or _
OnlyExtention="png" or _
OnlyExtention="gif" or _
OnlyExtention="swf" or _
OnlyExtention="mov" or _ then
call SaveFile(curDir & "\" & OnlyFileName, FileData)
end ifASP.NET allows for the easy creation of upload handler scripts. The following ASP.NET page allows files to be uploaded. The fileupload.aspx page does not process the upload, this task is performed by the fileupload.aspx.cs page.
The location of the image upload handler script must be defined within the XML 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.
This example script uploads images to the directory specified by the imageDir variable. In order for images to function correctly within EditLive! for XML the base attribute of the <httpImageUpload> element must reflect the location of the directory where images are to be stored on the Web server.
Ephox has written a sample image upload handler script using Active Server Pages and VBScript. This script can be found at SDK_INSTALL\webfolder\uploadscripts\aspnet\fileUpload.aspx and SDK_INSTALL\webfolder\uploadscripts\aspnet\fileUpload.aspx.cs where SDK_INSTALL represents the location where the EditLive! for XML SDK is installed.
Example 10.3. Example ASP.NET Image Upload Script
ASP .NET allows for the easy creation of upload handler scripts. The following ASP .NET page allows files to be uploaded. The fileupload.aspx page does not process the upload, this task is performed by the fileupload.aspx.cs page. The code for the fileupload.aspx page is as follows:
<%@ Page language="c#" Codebehind="fileupload.aspx.cs"
AutoEventWireup="false" Inherits="Ephox.FileUpload" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>fileupload</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="fileupload" method="post" runat="server">
</form>
</body>
</HTML>The POST is then handled in the Page_Load method of the fileupload.aspx.cs page. This appears as follows:
private void Page_Load(object sender, System.EventArgs e)
{
/*
* Set the "path" variable to the location where images are to be stored
*/
string path = "../images";
HttpFileCollection files;
files = Page.Request.Files;
for(int index=0; index < files.AllKeys.Length; index++)
{
HttpPostedFile postedFile = files[index];
string fileName = null;
int lastPos = postedFile.FileName.LastIndexOf('\\');
fileName = postedFile.FileName.Substring(++lastPos);
//Check the file type through the extension
if(fileName.EndsWith("jpg") || fileName.EndsWith("jpeg") ||
fileName.EndsWith("gif") || fileName.EndsWith("png") ||
fileName.EndsWith("tiff"))
{
postedFile.SaveAs(MapPath(path + "/" + fileName));
}
}
}Below are the steps required to use the ASP.NET image upload handler from above with EditLive! for XML in your own Web application.
For image upload, one line of code in the fileUpload.aspx.cs 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/fileUpload.aspx then setting the path variable to ../images would upload the images to a directory with the URL http://www.yourserver.com/images/.
string path = "../images";
Relative paths specified within the image upload acceptor script are relative to the Web accessible location of the image upload acceptor script.
EditLive! for XML's configuration file should now be edited to reflect the changes made in the previous step. You will find these settings within the <httpUpload> element. The URL setting should reflect the location of the fileUpload.aspx file on your Web server.
The following example reflects the setting of the href attribute of the <httpImageUpload> element if the upload script could be found at the URL http://www.yourserver.com/scripts/fileUpload.aspx.
<editLive>
...
<mediaSettings>
<httpUpload
base= ...
href="http://www.yourserver.com/scripts/fileUpload.aspx"
/>
...
</mediaSettings>
...
</editLive>Finally the HTTP Image Upload base attribute should be changed to reflect the location where images can be found on your Web server.
This location may not be the same value as that used within the upload acceptor script, above. Rather, it will be the virtual directory alias used by your Web server for the location listed in upload acceptor script.
This example follows from the code above. It uses an absolute URL as the value of the base attribute. The value of the base attribute corresponds to the URL that for the directory that images are uploaded to.
<editLive>
...
<mediaSettings>
<httpImageUpload
base="http://www.yourserver.com/images/"
href="http://www.yourserver.com/scripts/fileUpload.aspx"
/>
...
</mediaSettings>
...
</editLive>The ASP.NET upload acceptor script provided with EditLive! for XML can, by default, only be used with common image file types. This is restricted by inspecting the extension of an uploaded file. Support for other file types, including multimedia object types such as Macromedia Flash (.swf) and Apple QuickTime (.mov) can easily be added by adding the relevant extension to the list of allowed extensions in the upload fileupload.aspx.cs portion of the acceptor script.
The list of permitted extensions can be found as follows in the ASP.NET fileupload.aspx.cs upload acceptor script file in the following statement:
HttpFileCollection files;
files = Page.Request.Files;
for(int index=0; index < files.AllKeys.Length; index++)
{
HttpPostedFile postedFile = files[index];
string fileName = null;
int lastPos = postedFile.FileName.LastIndexOf('\\');
fileName = postedFile.FileName.Substring(++lastPos);
//Check the file type through the extension
if(fileName.EndsWith("jpg") || fileName.EndsWith("jpeg") ||
fileName.EndsWith("gif") || fileName.EndsWith("png") ||
fileName.EndsWith("tiff"))
{
postedFile.SaveAs(MapPath(path + "/" + fileName));
}
}The example below demonstrates how this example can be extended to handle Flash and QuickTime files, note the addition of the file extensions to the if statement in the code below:
HttpFileCollection files;
files = Page.Request.Files;
for(int index=0; index < files.AllKeys.Length; index++)
{
HttpPostedFile postedFile = files[index];
string fileName = null;
int lastPos = postedFile.FileName.LastIndexOf('\\');
fileName = postedFile.FileName.Substring(++lastPos);
//Check the file type through the extension
if(fileName.EndsWith("jpg") || fileName.EndsWith("jpeg") ||
fileName.EndsWith("gif") || fileName.EndsWith("png") ||
fileName.EndsWith("tiff") || fileName.EndsWith("swf") ||
fileName.EndsWith("move"))
{
postedFile.SaveAs(MapPath(path + "/" + fileName));
}
}This article provides a sample script, written using a Java servlet, to upload image file via a HTTP POST. Instructions on how it can be tailored for use in Web applications are also included.
The location of the image upload handler script must be defined within the XML 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.
This example script uploads images to the directory specified by the FILEDIR property within the FILEUPLOAD.properties file. In order for images to function correctly within EditLive! for XML the base attribute of the <httpUpload> element must reflect the location of the directory where images are uploaded to on the Web server.
The JSP Image Upload Script provided with EditLive! for XML is dependant on the Apache Commons FileUpload and Logging packages. These packages are provided with the source for the JSP upload script in the SDK_INSTALL\webfolder\uploadscripts\jsp\lib directory where SDK_INSTALL is the directory where the EditLive! for XML SDK is installed. The source for the example script can be found in the UploadScript.java file.
An implementation of the J2EE servlet API is also required to use the same upload script. The servlet-api.jar file from the Apache Tomcat project has been included in the SDK_INSTALL\webfolder\uploadscripts\jsp\lib directory where SDK_INSTALL is the directory where the EditLive! for XML SDK is installed.
If this is not the case please change the example code according to the location where this file can be found on your machine.
For file upload, the FILEDIR property in the FILEUPLOAD.properties file must be changed to indicate the location to which files are to be uploaded. Changing the FILEUPLOAD.properties does not require UploadScript.java to be recompiled.
FILEDIR=C:\\webserver\\webapp\\images\\
Should you wish to alter the UploadScript.java file it must be recompiled for the changes to take effect. Once you have completed your changes save the file. The file must now be compiled into a .class file. To compile this file you will need to run the Java compiler.
To run the Java compiler use the javac command from the command line. This command takes the form of:
javac -classpath <files needed for compilation> <file for compilation> Files that are needed for compilation should be listed with a semi-colon (;) separating them. The compilation of the UploadTest.java file requires the Apache Commons FileUpload library, as well as the servlet library (servlet.jar).
If there are spaces present in either the classpath or filename arguments then these should be enclosed by quotation ("") marks as shown below. For example, the following would be the command line command which follows from the previous steps:
javac -classpath ".;C:\SDK_INSTALL\webfolder\uploadscripts\jsp\lib\commons-fileupload-1.0.jar; C:\SDK_INSTALL\webfolder\uploadscripts\jsp\lib\servlet-api.jar; C:\SDK_INSTALL\webfolder\uploadscripts\jsp\lib\commons-logging.jar" "C:\SDK_INSTALL\webfolder\uploadscripts\jsp\UploadScript.java"
These locations will change dependant on your install of the EditLive! for XML J2EE SDK and your Web server install. The location of the servlet-api.jar file will depend on which Web server you are using. The servlet-api.jar file may be replaced by an appropriate equivalent for your Web server.
After this file has been correctly compiled (ie. the Java compiler has generated no errors and the UploadScript.class file has been generated) the UploadScript.class file must be copied to the EditLive!_Java_Install/WEB-INF/classes directory (where EditLive_Java_Install represents the location that the EditLive! for XML SDK install used by your Web server can be found). Following from the previous examples the correct location for file would be:
C:\webserver\webapp\WEB-INF\classes\UploadScript.class
Once the UploadScript.class has been copied to the EditLive!_Java_Install/WEB-INF/classes directory (where EditLive_Java_Install represents the location that the EditLive! for XML SDK install used by your Web server can be found) the web.xml file of the application must include an appropriate servlet mapping. The following steps detail how to do this:
Declare the servlet alias for the UploadScript class. The following XML declares uploadScript servlet alias for the UploadScript class. The <servlet-name> element contains the servlet alias while the <servlet-class> tag contains the name of the class (found within the WEB-INF/lib directory of the Web application) to be used for the servlet.
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>
uploadScript
</servlet-name>
<servlet-class>
UploadScript
</servlet-class>
</servlet>
...Map a URL pattern to the servlet. The servlet will then be used to process HTTP requests corresponding to the URL pattern. The context for the URL pattern is the current Web application. Thus a mapping of /uploadscript within the application editlivejava would process all requests to the http://webserver/editlivejava/uploadscript URL where webserver represents the host server.
The following example maps the uploadScript servlet (as specified above) to the /uploadscript URL pattern. The <servlet-name> element contains the servlet alias name and the <url-pattern> contains the URL pattern to be used to map to that servlet.
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
...
</servlet>
<servlet-mapping>
<servlet-name>
uploadScript
</servlet-name>
<url-pattern>
/uploadscript
</url-pattern>
</servlet-mapping>
...
</webapp>Below are the steps required to use the JSP image upload handler with EditLive! for XML in your own Web application.
EditLive! for XML's configuration file should now be edited to reflect the changes made in the previous step. You will find these settings within the <httpUpload> element. The URL setting should reflect the location of the UploadScript.class file on your Web server.
The following example reflects the setting of the href attribute of the <httpImageUpload> element if the upload script could be found at the URL http://www.yourserver.com/webapp/uploadscript. See the previous section for information on how to configure the URL mapping for the upload script.
<editLive>
...
<mediaSettings>
<httpUpload
base= ...
href="http://www.yourserver.com/webapp/uploadscript"
/>
...
</mediaSettings>
...
</editLive>Finally the HTTP Image Upload base attribute should be changed to reflect the location where images can be found on your Web server.
This location may not be the same value as that used within the upload acceptor script, above. Rather, it will be the virtual directory alias used by your Web server for the location listed in upload acceptor script.
This example follows from the code above. It uses an absolute URL as the value of the base attribute. The value of the base attribute corresponds to the URL that for the directory that images are uploaded to.
<editLive>
...
<mediaSettings>
<httpUpload
base="http://www.yourserver.com/webapp/images/"
href="http://www.yourserver.com/webapp/uploadscript"
/>
...
</mediaSettings>
...
</editLive>The Java (JSP) upload acceptor script provided with EditLive! for XML can, by default, only be used with common image file types. This is restricted by inspecting the extension of an uploaded file. Support for other file types, including multimedia object types such as Macromedia Flash (.swf) and Apple QuickTime (.mov) can easily be added by adding the relevant extension to the list of allowed extensions in the acceptor script's FILEUPLOAD.properties file.
To add the required extensions simply edit the FILEEXT property of the FILEUPLOAD.properties file. This property is a comma-delimited-list of extensions. Once you have specified the required extension it is recommended that the server be restarted so that the change may take effect.
The list of permitted extensions can be found as follows in the FILEUPLOAD.properties file:
FILEEXT=jpg,jpeg,tiff,png,gif
The example below demonstrates how this example can be extended to handle Flash and QuickTime files, note the addition of the file extensions to the property declaration below:
FILEEXT=jpg,jpeg,tiff,png,gif,swf,mov
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.
The location of the image upload handler script must be defined within the XML 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.
This example script uploads images to the directory specified by the imageFolder variable. In order for images to function correctly within EditLive! for XML the base attribute of the <httpImageUpload> element must reflect the location of the directory where images on the Web server.
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/";Reset the HTTP_POST_FILES array, and store the first element in the variable temp.
reset ($HTTP_POST_FILES); $temp = current($HTTP_POST_FILES);
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];
copy($temp[tmp_name], $filetowrite);If the variable is not an uploaded file, return an error.
} else {
// Notify ELJ that the upload failed
header("HTTP/1.0 500 Server Error");
}
?>Ephox 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! for XML SDK is installed.
Below are the steps required to use the PHP image upload handler in your own Web application.
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.
Using the configuration tool, change to the Media Settings tab.
Find the Image Upload section.
Under Image Upload Script, enter php_postacceptor.php; if the file is not located in the same folder as your other script pages you will need to include the HTTP path as well.
For more information, see HTTP File Upload - href.
Under Image Upload Base URL, enter the HTTP path to the folder where your images will be stored.
This location is not always the same value as that used within the upload acceptor script, above. Rather, it will be the directory used to access the folder via a web browser. For more information, see HTTP File Upload - base.
Open your configuration file in any text editor (eg Notepad on Windows).
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>The href attribute is the same as the Image Upload Script setting in the configuration tool.
The base attribute is the same as the Image Upload Base URL setting in the configuration tool.
This article provides a sample script, written using ColdFusion, 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.
The location of the image upload handler script must be defined within the XML 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.
This example script uploads images to the directory specified by the imageFolder variable. In order for images to function correctly within EditLive! for XML the base attribute of the <httpImageUpload> element must reflect the location of the directory where images on the Web server.
Use the <CFSETTING> tag to prevent extra whitespace from being written to the output. ELJ uses all output returned for the saved filename; extra whitespace will cause image URLs to be incorrect. For this reason the <CFSETTING> tag must be the first thing in the document.
<CFSETTING EnableCFOutputOnly="Yes"> <!--- The above ensures only the <cfoutput> tag causes any output; ELJ includes extra whitespace as part of the file name. --->
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 *
*********************************************--->
<cfset uploadFolder="images">Use the expandPath function to get the full path of the folder on the server.
<cfset imageFolder=expandPath("#uploadFolder#")>Save the uploaded file to the images folder.
<!--- Save the uploaded file ---> <cffile action = "upload" fileField = "image" destination = "#imageFolder#" nameConflict = "MakeUnique">
Return the name of the file to ELJ in case the MakeUnique script directive caused the file to be renamed.
<!--- Notify ELJ of the filename ---> <cfoutput>#serverFile#</cfoutput>
Ephox has written a sample image upload handler script using ColdFusion. This script can be found at SDK_INSTALL\webfolder\uploadscripts\coldfusion\coldfusion_postacceptor.chm where SDK_INSTALL represents the location where the EditLive! for XML SDK is installed.
Below are the steps required to use the ColdFusion image upload handler in your own Web application.
For image upload, one line of code in the coldfusion_postacceptor.chm 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/coldfusion_postacceptor.chm 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.
Using the configuration tool, change to the Media Settings tab.
Find the Image Upload section.
Under Image Upload Script, enter coldfusion_postacceptor.chm; if the file is not located in the same folder as your other script pages you will need to include the HTTP path as well.
For more information, see HTTP File Upload - href.
Under Image Upload Base URL, enter the HTTP path to the folder where your images will be stored.
This location is not always the same value as that used within the upload acceptor script, above. Rather, it will be the directory used to access the folder via a web browser. For more information, see HTTP File Upload - base.
Open your configuration file in any text editor (eg Notepad on Windows).
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="coldfusion_postacceptor.chm">
</httpUpload>
...
</mediaSettings>The href attribute is the same as the Image Upload Script setting in the configuration tool.
The base attribute is the same as the Image Upload Base URL setting in the configuration tool.
Copyright 2001-2005 Ephox Corporation. All Rights Reserved.