\JUpload
This class manage upload, with use of the JUpload applet. It's both a sample to show how to use the applet, and a class you can use directly into your own application.
Recommandation: Don't update its code !
By doing this, you'll be able to reuse directly any update coming from the JUpload project, instead of reporting your
modifications into any new version of this class. This guarantees you that your project can use the last version of
JUpload, without any code modification. We work so that the applet behavior remains unchanged, but from time to time,
a change can appear.
Sample:
- See the index.php samples, in the same folder.
Notes:
- maxChunkSize: this class use a default maxChunkSize of 500K (or less, depending on the script max size). This allows
upload of FILES OF ANY SIZE on quite all ISP hosting. If it's too big for you (the max upload size of your ISP is less
than 500K), or if you want no chunk at all, you can, of course, override this default value.
Parameters:
- $appletparams contains a map for applet parameters: key is the applet parameter name. The value is the value to transmit
to the applet. See the applet documentation for information on all applet parameters.
- $classparams contains the parameter specific for the JUpload class below. Here are the main class parameters:
- demo_mode. Files are uploaded to the server, but not stored on its hard drive. That is: you can simulate the global
behavior, but won't consume hard drive space. This mode is used on sourceforge web site.
Output generated for uploaded files:
- $files is an array of array. This can be managed by (a) the function given in the callbackAfterUploadManagement class
parameter, or (b) within the page whose URL is given in the afterUploadURL applet parameter, or (c) you can Extend the
class and redeclare defaultAfterUploadManagement() to your needs.
See the defaultAfterUploadManagement() for a sample on howto manage this array.
This array contains:
- One entry per file. Each entry is an array, that contains all files properties, stored as $key=>$value.
The available keys are:
- name: the filename, as it is now stored on the system.
- size: the file size
- path: the absolute path, where the file has been stored.
- fullName: the canonical file name (i.e. including the absolute path)
- md5sum: the md5sum of the file, if further control is needed.
- mimetype: the calculated mime type of the file
- If the formData applet parameter is used: all attributes (key and value) uploaded by the applet, are put here,
repeated for each file.
Note: if you are using a callback function (i.e. callbackAfterUploadManagement) and you do not see a global 'object' you
are expecting then it might have been destroyed by PHP - c.f. http://bugs.php.net/bug.php?id=39693
Synopsis
- // members
- public $appletparams;
- public $classparams;
- public $files;
- // methods
- public void JUpload()
- public void uploadedfiles()
- protected void logDebug()
- protected void logPHPDebug()
- private void arrayexpand()
- private void tobytes()
- private A str_jsinit()
- private A str_applet()
- private void abort()
- private void warning()
- private void cleanup()
- private void mkdirp()
- private void dstfinal()
- public void defaultAfterUploadManagement()
- private void generateAppletTag()
- public void interceptBeforeUpload()
- public void interceptAfterUpload()
- private void receive_debug_log()
- private void receive_uploaded_files()
- private void page_start()
Members
public
- $appletparams
- $classparams
- $files
Methods
private
- abort()
- arrayexpand()
- cleanup()
- dstfinal() — This method: - Replaces some potentially dangerous characters by '_' (in the given name an relative path) - Checks if a files of the same name already exists.
- generateAppletTag() — Generation of the applet tag, and necessary things around (js content). Insertion of this into the content of the page.
- mkdirp()
- page_start()
- receive_debug_log() — This method manages the receiving of the debug log, when an error occurs.
- receive_uploaded_files() — This method is the heart of the system. It manage the files sent by the applet, check the incoming parameters (md5sum) and reconstruct the files sent in chunk mode.
- str_applet() — Build a string, containing the applet tag with all parameters.
- str_jsinit() — Build a string, containing a javascript wrapper function for setting applet properties via JavaScript. This is necessary, because we use the "modern" method of including the applet (using <object> resp. <embed> tags) in order to trigger automatic JRE downloading.
- tobytes() — Convert a value ending in 'G','M' or 'K' to bytes
- warning()
protected
- logDebug() — Log a message on the current output, as a HTML comment.
- logPHPDebug() — Log a message to the PHP log.
public
- JUpload()
- defaultAfterUploadManagement() — Example function to process the files uploaded. This one simply displays the files' data.
- interceptAfterUpload() — This function displays the uploaded files description in the current page (see tag_flist class parameter)
- interceptBeforeUpload() — This function is called when constructing the page, when we're not reveiving uploaded files. It 'just' construct the applet tag, by calling the relevant function.
- uploadedfiles() — Return an array of uploaded files * The array contains: name, size, tmp_name, error, relativePath, md5sum, mimetype, fullName, path