HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

ocPortal Developer's Guide: The uploads interface

» Return to Contents



ocPortal's upload system is very modular, and can be used by almost any part of ocPortal, without having to write any custom code!

sources/uploads.php

Global_functions_uploads.php

Function summary

void init__uploads ()
boolean is_swf_upload (boolean fake_prepopulation)
array get_url (ID_TEXT specify_name, ID_TEXT attach_name, ID_TEXT upload_folder, integer obfuscate, integer enforce_type, boolean make_thumbnail, ID_TEXT thumb_specify_name, ID_TEXT thumb_attach_name, boolean copy_to_server, boolean accept_errors, boolean should_get_something)
array _get_specify_url (ID_TEXT specify_name, ID_TEXT upload_folder, integer enforce_type, boolean accept_errors)
void _check_enforcement_of_type (string file, integer enforce_type, boolean accept_errors)
array _get_upload_url (ID_TEXT attach_name, ID_TEXT upload_folder, integer enforce_type, integer obfuscate, boolean accept_errors)

void init__uploads()

Standard code module initialisation function.

Parameters…

(No return value)


Return to the function index for this class Expand: View the source code to this function

boolean is_swf_upload(boolean fake_prepopulation)

Find whether an swfupload upload has just happened, and optionally simulate as if it were a normal upload (although 'is_uploaded_file'/'move_uploaded_file' would not work).

Parameters…

Name fake_prepopulation
Description Simulate population of the $_FILES array.
Default value boolean-false
Type boolean

Returns…

Description Whether an swfupload upload has just happened.
Type boolean

Return to the function index for this class Expand: View the source code to this function

array get_url(ID_TEXT specify_name, ID_TEXT attach_name, ID_TEXT upload_folder, integer obfuscate, integer enforce_type, boolean make_thumbnail, ID_TEXT thumb_specify_name, ID_TEXT thumb_attach_name, boolean copy_to_server, boolean accept_errors, boolean should_get_something)

Get URLs generated according to the specified information. It can also generate a thumbnail if required. It first tries attached upload, then URL, then fails.

Parameters…

Name specify_name
Description The name of the POST parameter storing the URL (if '', then no POST parameter). Parameter value may be blank.
Type ID_TEXT

Name attach_name
Description The name of the HTTP file parameter storing the upload (if '', then no HTTP file parameter). No file necessarily is uploaded under this.
Type ID_TEXT

Name upload_folder
Description The folder name in uploads/ where we will put this upload
Type ID_TEXT

Name obfuscate
Description Whether to obfuscate file names so the URLs can not be guessed/derived (0=do not, 1=do, 2=make extension .dat as well, 3=only obfuscate if we need to)
Default value 0
Type integer
Values restricted to 0 1 2 3

Name enforce_type
Description The type of upload it is (from an OCP_UPLOAD_* constant)
Default value 0
Type integer

Name make_thumbnail
Description Make a thumbnail (this only makes sense, if it is an image)
Default value boolean-false
Type boolean

Name thumb_specify_name
Description The name of the POST parameter storing the thumb URL. As before
Default value
Type ID_TEXT

Name thumb_attach_name
Description The name of the HTTP file parameter storing the thumb upload. As before
Default value
Type ID_TEXT

Name copy_to_server
Description Whether to copy a URL (if a URL) to the server, and return a local reference
Default value boolean-false
Type boolean

Name accept_errors
Description Whether to accept upload errors
Default value boolean-false
Type boolean

Name should_get_something
Description Whether to give a (deferred?) error if no file was given at all
Default value boolean-false
Type boolean

Returns…

Description An array of 4 URL bits (URL, thumb URL, URL original filename, thumb original filename)
Type array

Return to the function index for this class Expand: View the source code to this function

array _get_specify_url(ID_TEXT specify_name, ID_TEXT upload_folder, integer enforce_type, boolean accept_errors)

Filters specified URLs to make sure we're really allowed to access them.

Parameters…

Name specify_name
Description The name of the POST parameter storing the URL (if '', then no POST parameter). Parameter value may be blank.
Type ID_TEXT

Name upload_folder
Description The folder name in uploads/ where we will put this upload
Type ID_TEXT

Name enforce_type
Description The type of upload it is (from an OCP_UPLOAD_* constant)
Default value 0
Type integer

Name accept_errors
Description Whether to accept upload errors
Default value boolean-false
Type boolean

Returns…

Description A pair: the URL and the filename
Type array

Return to the function index for this class Expand: View the source code to this function

void _check_enforcement_of_type(string file, integer enforce_type, boolean accept_errors)

Ensures a given filename is of the right file extension for the desired file type.

Parameters…

Name file
Description The filename.
Type string

Name enforce_type
Description The type of upload it is (from an OCP_UPLOAD_* constant)
Type integer

Name accept_errors
Description Whether to accept upload errors
Default value boolean-false
Type boolean

(No return value)


Return to the function index for this class Expand: View the source code to this function

array _get_upload_url(ID_TEXT attach_name, ID_TEXT upload_folder, integer enforce_type, integer obfuscate, boolean accept_errors)

Converts an uploaded file into a URL, by moving it to an appropriate place.

Parameters…

Name attach_name
Description The name of the HTTP file parameter storing the upload (if '', then no HTTP file parameter). No file necessarily is uploaded under this.
Type ID_TEXT

Name upload_folder
Description The folder name in uploads/ where we will put this upload
Type ID_TEXT

Name enforce_type
Description The type of upload it is (from an OCP_UPLOAD_* constant)
Default value 0
Type integer

Name obfuscate
Description Whether to obfuscate file names so the URLs can not be guessed/derived (0=do not, 1=do, 2=make extension .dat as well)
Default value 0
Type integer
Values restricted to 0 1 2

Name accept_errors
Description Whether to accept upload errors
Default value boolean-false
Type boolean

Returns…

Description A pair: the URL and the filename
Type array

Return to the function index for this class Expand: View the source code to this function