Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 287 lines (178 sloc) 15.334 kb
fcc4fff @phiggins42 monster commit from moinconverter, which is always done prior to the …
phiggins42 authored
1 .. _dojox/form/Uploader:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
2
f89feb8 @wkeese regex change of level 1 headers to ====\nTEXT\n==== and level 2 heade…
wkeese authored
3 =======================
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
4 dojox.form.Uploader
5 =======================
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
6
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
7 :Project owner: Mike Wilcox
8 :Author: Mike Wilcox
8e25854 @wkeese :Available: --> :since:
wkeese authored
9 :since: 1.6
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
10
c15cbf2 @wkeese standardize spacing on directives like .. js
wkeese authored
11 .. contents ::
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
12 :depth: 3
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
13
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
14 A widget that adds functionality to a standard HTML file input which allows file uploading to a server. The widget hides the actual uploader and substitutes a dijit.form.Button, so that the file input matches the rest of the user interface. If the browser supports the HTML5 file input specification, that functionality is used. If it is not supported (IE or older browsers) plugins are available to enhance the Uploader.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
15
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
16 **The dojox.form.Uploader is an improvement upon, and replaces the dojox.form.FileUploader**. The multiple problems created by Flash are avoided because it is not used in Mozilla and Webkit browsers. Support for FileUploader will cease as of 1.6, but the code will remain until 2.0 for backwards compatibility.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
17
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
18 Features
19 ========
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
20
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
21 - The Uploader is a Dijit, and supports all the same functionality as any other form widget. FileUploader made this claim, but it still had trouble due to its late build process and dependency on the Flash plugin.
22 - The Uploader may be placed in a form and will "just work". Actually, the Uploader will block the form's submit event and take over its duties of collecting the field values and uploading the data to the server using the form's action attribute, or the url property given to the Uploader.
23 - The tabIndex attribute is supported.
24 - An additional widget, dojox.form.uploader.FileList is provided to show the selection set and visualize the upload progress.
25 - :ref:`dojox.form.uploader.FileList <dojox/form/uploader/FileList>`
da94b0e @wkeese tabs --> spaces
wkeese authored
26
a18758e @mwilcox Adding AMD notes
mwilcox authored
27 Important AMD Note
28 ------------------
eb01c1d @mwilcox Adding AMD notes
mwilcox authored
29
a18758e @mwilcox Adding AMD notes
mwilcox authored
30 When using the Uploader programmatically, you cannot use the reference argument from require() - you must use the global. This is because the plugins redefine the original Uploader class, and AMD does not allow time for this to happen. In other this will NOT work:
eb01c1d @mwilcox Adding AMD notes
mwilcox authored
31
32 .. js ::
33
a18758e @mwilcox Adding AMD notes
mwilcox authored
34 require(['dojox/form/Uploader', 'dojox/form/uploader/plugins/Flash'], function(Uploader){
35 myUploader = Uploader(...);
36 });
eb01c1d @mwilcox Adding AMD notes
mwilcox authored
37
38 Until 2.0, you must use:
39
40 .. js ::
41
a18758e @mwilcox Adding AMD notes
mwilcox authored
42 require(['dojox/form/Uploader', 'dojox/form/uploader/plugins/Flash'], function(Uploader){
43 myUploader = new dojox.form.Uploader(...); // disregard reference argument
44 });
eb01c1d @mwilcox Adding AMD notes
mwilcox authored
45
a18758e @mwilcox Adding AMD notes
mwilcox authored
46 Important Form Note
47 -------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
48
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
49 Because the Uploader uses your existing form, you must set its *enctype* to "multipart/form-data" which is used for uploading files.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
50
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
51 Missing Features
52 ----------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
53
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
54 The Uploader mimics the functionality of HTML5 file inputs, so some features available in the FileUploader are not (yet) available in Uploader. Specifically missing is the ability to add remove files from a current selection set. There are plans to implement this functionality soon.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
55
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
56 File mask (restricting the selection to certain file types) is in the HTML5 spec but missing from browser functionality. It is not supported.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
57
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
58 Usage
59 =====
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
60
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
61 The Uploader can be used in several variations.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
62
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
63 Uploader without Plugins
64 ------------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
65
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
66 The Uploader with no plugins is in "Form" mode. This mode will not do an Ajax upload. It is expected that you plan to handle the upload yourself, whether via Ajax or changing the entire page via a POST. Only form POSTs will work and they will navigate to the UploadFile.php page in the test files. Multiple file selection is used in browsers that support it, and in the others, multiple selections are added one at a time by adding file inputs.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
67
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
68 Uploader with the HTML5 Plugin
69 ------------------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
70
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
71 The HTML5 Uploader plugin does not support IE, it is more of a base class for IFrame or Flash, or used in cases where IE is not a requirement. For HTML5-capable browsers, this plugin provides an Ajax upload.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
72
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
73 Uploader with the IFrame Plugin
74 -------------------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
75
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
76 The IFrame plugin will use the IFrame to upload in IE. All other browsers will use the HTML5 plugin unless *force="iframe"* is used.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
77
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
78 Uploader with the Flash Plugin
79 ------------------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
80
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
81 The Flash plugin will use a SWF to upload in non-HTML5 browsers. All other browsers will use the HTML5 plugin, unless *force="flash"* is used, then Flash will be used in all browsers. *force="flash"* is provided because Flash has some features that HTML5 does not yet have. But it is still not recommended because of the many problems that Mozilla and Webkit have with the Flash plugin:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
82
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
83 - Changing the display style on the DOM element that holds a SWF will reset the SWF. This makes it difficult to support Flash in Dijit Tabs and Dialog boxes.
84 - Initialization of a SWF is not always consistent and occasionally throws errors.
85 - HTTPS support in Mozilla is problematic.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
86
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
87 These problems do not occur in IE.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
88
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
89 Setup
90 =====
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
91
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
92 Markup
93 ------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
94
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
95 To use the Uploader, simply require it and use the appropriate data-dojo-type in an input within a form:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
96
c49c87d @phiggins42 normalization
phiggins42 authored
97 .. js ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
98
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
99 dojo.require("dojox.form.Uploader");
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
100
c49c87d @phiggins42 normalization
phiggins42 authored
101 .. html ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
102
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
103 <form method="post" action="UploadFile.php" id="myForm" enctype="multipart/form-data" >
459b3a1 @wkeese dojoType --> data-dojo-type
wkeese authored
104 <input name="uploadedfile" multiple="true" type="file" data-dojo-type="dojox.form.Uploader" label="Select Some Files" id="uploader" />
105 <input type="submit" label="Submit" data-dojo-type="dijit.form.Button" />
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
106 </form>
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
107
108
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
109 Plugins will self initialize, so to use one, all that is needed is to require it. The following example uses the IFrame plugin, which inherits from the HTML5 plugin. So HTML5 file inputs are used when available and the IFrame technique used elsewhere (the HTML is exactly the same as the previous example):
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
110
c49c87d @phiggins42 normalization
phiggins42 authored
111 .. js ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
112
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
113 dojo.require("dojox.form.Uploader");
114 dojo.require("dojox.form.uploader.plugins.IFrame");
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
115
c49c87d @phiggins42 normalization
phiggins42 authored
116 .. html ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
117
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
118 <form method="post" action="UploadFile.php" id="myForm" enctype="multipart/form-data" >
459b3a1 @wkeese dojoType --> data-dojo-type
wkeese authored
119 <input name="uploadedfile" multiple="true" type="file" data-dojo-type="dojox.form.Uploader" label="Select Some Files" id="uploader" />
120 <input type="submit" label="Submit" data-dojo-type="dijit.form.Button" />
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
121 </form>
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
122
123
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
124 Programmatic
125 ------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
126
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
127 Programmatic creation is also supported as shown in the following example that includes the Flash plugin:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
128
c49c87d @phiggins42 normalization
phiggins42 authored
129 .. js ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
130
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
131 dojo.require("dojox.form.Uploader");
132 dojo.require("dojox.form.uploader.plugins.Flash");
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
133
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
134 var u = new dojox.form.Uploader({label:"Programmatic Uploader", multiple:true, uploadOnSelect:true, url:"UploadFile.php"});
135 dojo.byId("myDiv").appendChild(u.domNode);
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
136
137
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
138 The "name" Property
139 -------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
140
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
141 A key property to the Uploader is "name", which is subsequently used as the name attribute on the file input that is created, or as the field name that Flash assigns to each file. The default name is "uploadedfile" which works with the provided *UploadFile.php*. The HTML5 spec specifies that attributes that are array-like should use square brackets at the end of the field name. If a HTMl5-capable browser is used, the Uploader appends these brackets. It also appends an "s" at the end to help the server script determine the file data. If the Flash plugin is in use, the Uploader appends "Flash" to the end of the name, or whatever the "flashFieldName" property is set to. If a standard file input is in use (in "Form" mode or IFrame), the name is left as-is.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
142
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
143 The variations of the *name* attribute is necessary so that the server page knows what is being sent and can handle it appropriately.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
144
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
145 Other Properties
146 ----------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
147
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
148 - **flashFieldName** Is the text appended to the *name* property. This is necessary so the server can tell what type of file data it is dealing with.
149 - **multiple** Whether multiple files can or cannot be selected.
150 - **url** If you don't supply an *action* in your form, supply an *url* to upload to.
151 - **label** The text used in the button.
40dc7a9 @wkeese dojox/ spelling
wkeese authored
152 - **tabIndex** Defaults to "0". You change this to change the tab order on the page.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
153
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
154 The Flash plugin has other properties specific to that file.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
155
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
156 Methods
157 -------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
158
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
159 Because the Uploader without plugins doesn't upload, there are only the following methods:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
160
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
161 - **reset** Clears the list of selected files.
162 - **getFileList** Returns an array of objects representing the file data.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
163
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
164 When using a plugin, the following methods will be available:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
165
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
166 - **upload** This method uploads the files and any data passed as an argument.
167 - **submit** This method uploads the files and if a form element is passed as an argument, it is converted into a JavaScript object.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
168
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
169 Server Side
170 ===========
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
171
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
172 The file data is uploaded to a temp folder on the server. It's a misconception that your server side language has something to do with this. Receiving an uploaded file is handled by your server, meaning Apache or IIS. Typically the file is placed in a temp folder and it is your job to move it from there to the upload destination. Whether HTML or Flash, the payload is done with a multipart transfer. After the upload is complete, the server script is called.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
173
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
174 During a Flash multi-file upload, the images are uploaded in parallel (unless deferredUploading=true), however, the server script only receives one file at a time. So if five files are uploaded, the server script will be called five times.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
175
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
176 During an HTML multi-file upload, the files are all uploaded at once, and after all five are completely uploaded to the temp folder, the server script is called just once. For traditional HTML (Form mode or IFrame plugin) each file will be referenced as numerically sequenced fields: uploadedfile0, uploadedfile1, uploadedfile2, etc. For HTML5 uploads, the server script looks for "uploadedfiles" (with an "s"). the Uploader also added square brackets to the name ("uploadedfiles[]") to match the spec. The result is the files are given to the server script as an actual array.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
177
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
178 With a multipart request the POST data is the contents for the first part and the uploaded files is an array (or an object) of each additional part. Refer to your particular server documentation for how to reference the files (PHP is used as an example in the next section).
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
179
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
180 The return data needs to be formatted very specifically, and there are different formats for Flash and HTML. See **Server Side Return Data** below.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
181
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
182 Server Side Code PHP
183 --------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
184
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
185 Uploader comes with a working PHP file, *dojox/form/tests/UploadFile.php*, to use as a reference for how your server side code should work. UploadFile.php has two dependencies, *dojo/tests/resources/JSON.php*, which is used for converting the return data to a JSON string, and *dojox/form/tests/cLog.php* which is used to log message to a text file, placed relative to the PHP file.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
186
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
187 UploadFile.php is expecting one of four things:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
188
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
189 1) A file or files from Flash (uploadedfilesFlash)
da94b0e @wkeese tabs --> spaces
wkeese authored
190 2) A file from HTML (uploadedfiles0)
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
191 3) Multiple files from HTML (uploadedfiles0, uploadedfiles1, etc)
192 4) A file array from HTML5 (uploadedfiles[])
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
193
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
194 The PHP file is inspecting the header and looking for the parameters set in Uploader. Whatever you set these parameters to, they must match on the server.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
195
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
196 The field name for the HTML uploader works much the same way. The only difference is if you do multi-file upload with HTML, this essentially continues to add fileInputs to the form, and in doing so, appends numbers to the fileInput field names, starting with '0'. That's why one file fieldname will look like "myFieldName" but two files will look like [ "myFieldName0", "myFieldName1" ] to the server side code.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
197
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
198 Server Side Return Data
199 -----------------------
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
200
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
201 How the data is returned from the server is not difficult, but it is very important. If not done correctly, it can be the cause of reported errors that the "onComplete" is not firing in Uploader.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
202
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
203 **NOTE** The Flash uploader and the HTML uploader need differently formatted return data. You will need to inspect the post data to determine which type to return.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
204
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
205 If *uploadedfilesFlash* is found in the post data and Flash is being used on the client side, all that is needed for return data is a key-value string, and it can simply be returned, as at the end of a function. Flash will parse these key-value pairs into an object and pass it to javaScript. You may also want to insert *exit* or whatever necessary to cease execution of the remainder of the code. Example:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
206
c49c87d @phiggins42 normalization
phiggins42 authored
207 .. html ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
208
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
209 $data .='file='.$file.',name='.$name.',width='.$width.',height='.$height.',type='.$type;
210 echo($data);
211 exit;
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
212
40dc7a9 @wkeese dojox/ spelling
wkeese authored
213 For non-PHP developers this translates to:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
214
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
215 .. code-block :: text
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
216
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
217 $name = name of the file, such as "PIC01.jpg"
218 $file = name of the file and the path, such as "uploaded/PIC01.jpg"
219 $width, $height = the dimensions (if you are working with images)
220 $type = the extension of the file - JPG, GIF, PNG, etc.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
221
222
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
223 The return to Flash should look like:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
224
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
225 .. code-block :: text
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
226
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
227 "file=uploaded/PIC01.jpg,name=PIC01.jpg,width=320,height=240,type=jpg"
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
228
229
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
230 This string should be returned, or printed, or echoed.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
231
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
232 You can add an error key if one file was in error; say if it was not of the correct type. This error code or message will be returned in the onComplete dataArray. It's important to note that as far as the Uploader is concerned, everything was a success. It's up to your custom code to test for this error.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
233
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
234 The return string with an error might look like:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
235
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
236 .. code-block :: text
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
237
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
238 "file=uploaded/PIC01.jpg,name=PIC01.jpg,width=320,height=240,type=jpg,error=Not recognized file type"
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
239
40dc7a9 @wkeese dojox/ spelling
wkeese authored
240 You can also send back arbitrary parameters from your server-side script using this comma-delimited format. For example, adding variables foo and abc:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
241
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
242 .. code-block :: text
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
243
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
244 "file=uploaded/PIC01.jpg,name=PIC01.jpg,width=320,height=240,type=jpg,foo=bar,abc=123"
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
245
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
246 Then you can access these variables in the client-side functions using dataArray[i].additionalParams.foo and dataArray[i].additionalParams.abc.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
247
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
248 If IFrame plugin is used, the code on the client side gets tricky, as reading back from an iframe presents problems. In order to read the iframe return data accurately cross browser, the code needs to be wrapped in a *<textarea>*. You can see the code for this on the very last line of UploadFiles.php. Note that the textarea needs to be outside of the PHP. Example:
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
249
c49c87d @phiggins42 normalization
phiggins42 authored
250 .. html ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
251
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
252 <?php
253 ....code....
254 ?>
255 <textarea><?php print $json->encode($dataObject); ?></textarea>
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
256
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
257 For non-PHP devs, this translates into a JSON string, wrapped in a textarea, returned as HTML. I know it's screwy, but that's how it works.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
258
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
259 If you are having problems getting *onComplete* to fire, look at this code first. Often the problem is the server side code is not catching the field name for whatever reason (perhaps the client and server names don't match) and the code is falling to the end of the page and returning a textarea when it shouldn't.
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
260
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
261 Examples
262 ========
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
263
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
264 This example shows how to use Flash and IFrame plugins for both cases (browsers with and without flash).
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
265
4413e3b @wkeese yet more fixes removing unneeded <script> and <style> tags
wkeese authored
266 .. js ::
ffa767c @phiggins42 removing :linenos: rather than reverting previous commit. revert both…
phiggins42 authored
267
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
268 dojo.require("dojox.form.Uploader");
269 dojo.require("dojox.embed.Flash");
67f7d9e @wkeese Fix spacing for braces, function(), if(), while(), for(), else, etc. …
wkeese authored
270 if(dojox.embed.Flash.available){
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
271 dojo.require("dojox.form.uploader.plugins.Flash");
67f7d9e @wkeese Fix spacing for braces, function(), if(), while(), for(), else, etc. …
wkeese authored
272 }else{
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
273 dojo.require("dojox.form.uploader.plugins.IFrame");
274 }
49acd5c @wkeese change dojo.addOnLoad() --> dojo.ready(), except for:
wkeese authored
275 dojo.ready(function(){
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
276 var u = new dojox.form.Uploader({
277 label: "Select files",
278 multiple: true,
279 uploadOnSelect: true,
280 url: "UploadFile.php",
281 }, "uploader");
f336711 @peller Close statement
peller authored
282 });
4413e3b @wkeese yet more fixes removing unneeded <script> and <style> tags
wkeese authored
283
284 .. html ::
d608cc5 @phiggins42 \r\n -> \n conversion.
phiggins42 authored
285
9dd52dc @phiggins42 mondo whitespace change
phiggins42 authored
286 <div id="uploader"></div>
Something went wrong with that request. Please try again.