Procedural File: fileUpload.lib.php
Source Location: /main/inc/lib/fileUpload.lib.php
Page Details:
This is the file upload library for Dokeos.
Include/require it in your code to use its functionality.
Tags:
add_all_documents_in_folder_to_database [line 1876]
void add_all_documents_in_folder_to_database(
$_course, $user_id, string $base_work_dir, [ $current_path = ''], [ $to_group_id = 0], string $current_path,)
|
|
This recursive function can be used during the upgrade process form older versions of Dokeos It crawls the given directory, checks if the file is in the DB and adds it if it's not
Parameters
| string |
$base_work_dir |
|
| string |
$current_path, |
needed for recursivity |
| |
$_course |
|
| |
$user_id |
|
| |
$current_path |
|
| |
$to_group_id |
|
add_document [line 1187]
id add_document(
array $_course, string $path, string $filetype, int $filesize, string $title, [ $comment = NULL], [ $readonly = 0])
|
|
Adds a new document to the database
Tags:
Parameters
| array |
$_course |
|
| string |
$path |
|
| string |
$filetype |
|
| int |
$filesize |
|
| string |
$title |
|
| |
$comment |
|
| |
$readonly |
|
add_ext_on_mime [line 659]
- add_ext_on_mime(
- $fileName, - $fileType)
|
|
Try to add an extension to files without extension Some applications on Macintosh computers don't add an extension to the files. This subroutine try to fix this on the basis of the MIME type sent by the browser. Note : some browsers don't send the MIME Type (e.g. Netscape 4). We don't have solution for this kind of situation
Tags:
Parameters
| - |
$fileName |
fileName (string) - Name of the file |
| - |
$fileType |
fileType (string) - Type of the file |
api_replace_links_in_html [line 1572]
void api_replace_links_in_html(
$upload_path, $full_file_name)
|
|
Parameters
| |
$upload_path |
|
| |
$full_file_name |
|
api_replace_links_in_string [line 1602]
void api_replace_links_in_string(
$upload_path, $buffer)
|
|
Parameters
api_replace_parameter [line 1714]
void api_replace_parameter(
$upload_path, $buffer, [ $param_name = "src"])
|
|
OK find all tags in that string with the specified parameter (like href or src) OK for every one of these tags, find the src|href|... part to edit it OK change the src|href|... part to use download.php (or showinframes.php) OK do some special stuff for hyperlinks OK if download.php or showinframes.php is already in the tag, leave it alone OK if mailto is in the tag, leave it alone OK if the src|href param contains http://, it's absolute --> leave it alone OK add target="_top" OK use showinframes.php instead of download.php
Parameters
| |
$upload_path |
|
| |
$buffer |
|
| |
$param_name |
|
build_missing_files_form [line 1839]
string build_missing_files_form(
array $missing_files, string $upload_path, string $file_name)
|
|
This builds a form that asks for the missing images in a html file maybe we should do this another way?
Tags:
Parameters
| array |
$missing_files |
|
| string |
$upload_path |
|
| string |
$file_name |
|
check_for_missing_files [line 1818]
array check_for_missing_files(
string $file)
|
|
Checks the extension of a file, if it's .htm or .html we use search_img_from_html to get all image paths in the file
Tags:
Parameters
clean_up_files_in_zip [line 1077]
1 clean_up_files_in_zip(
$p_event $p_event, $p_header &$p_header)
|
|
this function is a callback function that is used while extracting a zipfile http://www.phpconcept.net/pclzip/man/en/index.php?options-pclzip_cb_pre_extract
Tags:
Parameters
| $p_event |
$p_event |
|
| $p_header |
&$p_header |
|
clean_up_path [line 1094]
$path clean_up_path(
&$path, string $path)
|
|
this function cleans up a given path by eliminating dangerous file names and cleaning them
Tags:
Parameters
create_link_file [line 1548]
void create_link_file(
string $filePath, string $url)
|
|
Creates a file containing an html redirection to a given url
Tags:
Parameters
| string |
$filePath |
|
| string |
$url |
|
create_unexisting_directory [line 1422]
string create_unexisting_directory(
array $_course, int $user_id, $to_group_id, $to_user_id, $base_work_dir, $desired_dir_name, [ $title = null], string $desiredDirName)
|
|
creates a new directory trying to find a directory name that doesn't already exist (we could use unique_name() here...)
Tags:
Parameters
| array |
$_course |
current course information |
| int |
$user_id |
current user id |
| string |
$desiredDirName |
complete path of the desired name |
| |
$to_group_id |
|
| |
$to_user_id |
|
| |
$base_work_dir |
|
| |
$desired_dir_name |
|
| |
$title |
|
dir_total_space [line 568]
- dir_total_space(
- $dirPath)
|
|
Compute the size already occupied by a directory and is subdirectories
Tags:
Parameters
| - |
$dirPath |
dirPath (string) - size of the file in byte |
disable_dangerous_file [line 158]
string disable_dangerous_file(
string $filename)
|
|
this function executes our safety precautions more functions can be added
Tags:
Parameters
documents_total_space [line 614]
int documents_total_space(
[int $to_group_id = '0'])
|
|
Calculate the total size of all documents in a course
Tags:
Parameters
| int |
$to_group_id |
(to calculate group document space) |
enough_size [line 514]
- enough_size(
- $fileSize, - $dir, - $maxDirSpace)
|
|
Check if there is enough place to add a file on a directory on the base of a maximum directory size allowed
Tags:
Parameters
| - |
$fileSize |
fileSize (int) - size of the file in byte |
| - |
$dir |
dir (string) - Path of the directory whe the file should be added |
| - |
$maxDirSpace |
maxDirSpace (int) - maximum size of the diretory in byte |
enough_space [line 544]
boolean enough_space(
int $file_size, $max_dir_space, array $_course, int 2)
|
|
Check if there is enough place to add a file on a directory on the base of a maximum directory size allowed
Tags:
Parameters
| array |
$_course |
|
| int |
2 |
max_dir_space maximum size |
| int |
$file_size |
file_size size of the file in byte |
| |
$max_dir_space |
|
filter_extension [line 1119]
int filter_extension(
string &$filename)
|
|
Check if the file is dangerous, based on extension and/or mimetype. The list of extensions accepted/rejected can be found from api_get_setting('upload_extensions_exclude') and api_get_setting('upload_extensions_include')
Tags:
Parameters
| string |
&$filename |
filename passed by reference. The filename will be modified if filter rules say so! (you can include path but the filename should look like 'abc.html') |
get_document_title [line 196]
name get_document_title(
string $name)
|
|
Returns the name without extension, used for the title
Tags:
Parameters
get_levels [line 1294]
The get_levels(
path+filename $filename)
|
|
Returns the directory depth of the file.
Tags:
Parameters
| path+filename |
$filename |
eg: /main/document/document.php |
handle_uploaded_document [line 296]
path handle_uploaded_document(
array $_course, array $uploaded_file, string $base_work_dir, string $upload_path, int $user_id, [ $to_group_id = 0], [ $to_user_id = NULL], [int $maxFilledSpace = ''], [int $unzip = 0], [string $what_if_file_exists = ''], [boolean $output = true], int $to_group_id,, int $to_user_id,)
|
|
this function does the save-work for the documents. it handles the uploaded file and adds the properties to the database if unzip=1 and the file is a zipfile, it is extracted if we decide to save ALL kinds of documents in one database, we could extend this with a $type='document', 'scormdocument',...
Tags:
Parameters
| array |
$_course |
|
| array |
$uploaded_file |
($_FILES) |
| string |
$base_work_dir |
|
| string |
$upload_path |
|
| int |
$user_id |
|
| int |
$to_group_id, |
0 for everybody |
| int |
$to_user_id, |
NULL for everybody |
| int |
$maxFilledSpace |
|
| int |
$unzip |
1/0 |
| string |
$what_if_file_exists |
overwrite, rename or warn if exists (default) |
| boolean |
$output |
Optional output parameter. So far only use for unzip_uploaded_document function. If no output wanted on success, set to false. |
| |
$to_group_id |
|
| |
$to_user_id |
|
htaccess2txt [line 139]
string htaccess2txt(
string $filename)
|
|
Renames .htaccess & .HTACCESS tot htaccess.txt
Parameters
item_property_update_on_folder [line 1246]
void item_property_update_on_folder(
array $_course, string $path, int $user_id)
|
|
this function updates the last_edit_date, last edit user id on all folders in a given path
Parameters
| array |
$_course |
|
| string |
$path |
|
| int |
$user_id |
|
move_uploaded_file_collection_into_directory [line 1467]
void move_uploaded_file_collection_into_directory(
array $_course, array $uploaded_file_collection, string $base_work_dir, string $missing_files_dir, int $user_id, $to_group_id, $to_user_id, int $max_filled_space)
|
|
Handles uploaded missing images
Tags:
Parameters
| array |
$_course |
|
| array |
$uploaded_file_collection |
- follows the $_FILES Structure |
| string |
$base_work_dir |
|
| string |
$missing_files_dir |
|
| int |
$user_id |
|
| int |
$max_filled_space |
|
| |
$to_group_id |
|
| |
$to_user_id |
|
php2phps [line 125]
change the file name extension from .php to .phps Useful to secure a site !!
Tags:
Parameters
| - |
$fileName |
fileName (string) name of a file |
process_uploaded_file [line 214]
true process_uploaded_file(
array $uploaded_file)
|
|
This checks if the upload succeeded
Tags:
Parameters
| array |
$uploaded_file |
($_FILES) |
remove_accents [line 1926]
void remove_accents(
$string)
|
|
Parameters
replace_accents [line 109]
string replace_accents(
string $string)
|
|
Replaces all accentuated characters by non-accentuated characters for filenames, as well as special HTML characters by their HTML entity's first letter. Although this method is not absolute, it gives good results in general. It first transforms the string to HTML entities (ô, @oslash;, etc) then removes the HTML character part to result in simple characters (o, o, etc). In the case of special characters (out of alphabetical value) like and <, it will still replace them by the first letter of the HTML entity (n, l, ...) but it is still an acceptable method, knowing we're filtering filenames here...
Tags:
Parameters
| string |
$string |
The accentuated string |
replace_dangerous_char [line 86]
- replace_dangerous_char(
- $filename, [- $strict = 'loose'])
|
|
replaces "forbidden" characters in a filename string
Tags:
Parameters
| - |
$filename |
string $filename |
| - |
$strict |
string $strict (optional) remove all non-ASCII |
replace_img_path_in_html_file [line 1498]
void replace_img_path_in_html_file(
$originalImgPath, $newImgPath, $htmlFile)
|
|
Parameters
| |
$originalImgPath |
|
| |
$newImgPath |
|
| |
$htmlFile |
|
search_img_from_html [line 1368]
array search_img_from_html(
string $htmlFile)
|
|
retrieve the image path list in a html file
Tags:
Parameters
set_default_settings [line 1318]
void set_default_settings(
path,filename $upload_path, $filename, [ $filetype = "file"])
|
|
Adds file to document table in database
Tags:
Parameters
| path,filename |
$upload_path |
|
| |
$filename |
|
| |
$filetype |
|
treat_uploaded_file [line 739]
boolean treat_uploaded_file(
array $uploadedFile, string $baseWorkDir, string $uploadPath, int $maxFilledSpace, [ $uncompress = ''])
|
|
Tags:
Parameters
| array |
$uploadedFile |
- follows the $_FILES Structure |
| string |
$baseWorkDir |
- base working directory of the module |
| string |
$uploadPath |
- destination of the upload.
This path is to append to $baseWorkDir
|
| int |
$maxFilledSpace |
- amount of bytes to not exceed in the base working directory |
| |
$uncompress |
|
unique_name [line 175]
new unique_name(
string $path, string $name)
|
|
this function generates a unique name for a file on a given location filenames are changed to name_#.ext
Tags:
Parameters
| string |
$path |
|
| string |
$name |
|
unzip_uploaded_document [line 930]
boolean unzip_uploaded_document(
$uploaded_file, $upload_path, $base_work_dir, $max_filled_space, [boolean $output = true], [ $to_group_id = 0], array $uploadedFile, string $uploadPath, string $baseWorkDir, int $maxFilledSpace)
|
|
Manages all the unzipping process of an uploaded document This uses the item_property table for properties of documents
Tags:
Parameters
| array |
$uploadedFile |
- follows the $_FILES Structure |
| string |
$uploadPath |
- destination of the upload.
This path is to append to $baseWorkDir
|
| string |
$baseWorkDir |
- base working directory of the module
|
| int |
$maxFilledSpace |
- amount of bytes to not exceed in the base
working directory
|
| boolean |
$output |
Output switch. Optional. If no output not wanted on success, set to false. |
| |
$uploaded_file |
|
| |
$upload_path |
|
| |
$base_work_dir |
|
| |
$max_filled_space |
|
| |
$to_group_id |
|
unzip_uploaded_file [line 787]
boolean unzip_uploaded_file(
array $uploadedFile, string $uploadPath, string $baseWorkDir, int $maxFilledSpace)
|
|
Manages all the unzipping process of an uploaded file
Tags:
Parameters
| array |
$uploadedFile |
- follows the $_FILES Structure |
| string |
$uploadPath |
- destination of the upload.
This path is to append to $baseWorkDir
|
| string |
$baseWorkDir |
- base working directory of the module
|
| int |
$maxFilledSpace |
- amount of bytes to not exceed in the base
working directory
|
update_existing_document [line 1224]
boolean update_existing_document(
array $_course, int $document_id, int $filesize, [int $readonly = 0])
|
|
Update an existing document in the database as the file exists, we only need to change the size
Tags:
Parameters
| array |
$_course |
|
| int |
$document_id |
|
| int |
$filesize |
|
| int |
$readonly |
|
|