dokeos-library
[ class tree: dokeos-library ] [ index: dokeos-library ] [ all elements ]

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:

todo:  test and reorganise
filesource:  Source Code for this file








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  
[ Top ]



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:

return:  if inserted document


Parameters

array   $_course  
string   $path  
string   $filetype  
int   $filesize  
string   $title  
   $comment  
   $readonly  
[ Top ]



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:

return:  fileName (string)
author:  - Hugues Peeters <peeters@ipm.ucl.ac.be>
author:  - Bert Vanderkimpen


Parameters

-   $fileName   fileName (string) - Name of the file
-   $fileType   fileType (string) - Type of the file
[ Top ]



api_replace_links_in_html [line 1572]

void api_replace_links_in_html( $upload_path, $full_file_name)



Parameters

   $upload_path  
   $full_file_name  
[ Top ]



api_replace_links_in_string [line 1602]

void api_replace_links_in_string( $upload_path, $buffer)



Parameters

   $upload_path  
   $buffer  
[ Top ]



api_replace_parameter [line 1714]

void api_replace_parameter( $upload_path, $buffer, [ $param_name = &quot;src&quot;])

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  
[ Top ]



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:

return:  the form


Parameters

array   $missing_files  
string   $upload_path  
string   $file_name  
[ Top ]



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:

return:  paths
see:  check_for_missing_files() uses search_img_from_html()


Parameters

string   $file  
[ Top ]



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:

return:  (If the function returns 1, then the extraction is resumed)


Parameters

$p_event   $p_event  
$p_header   &$p_header  
[ Top ]



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

string   $path  
   &$path  
[ Top ]



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:

author:  Hugues Peeters <hugues.peeters@claroline.net>


Parameters

string   $filePath  
string   $url  
[ Top ]



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:

return:  actual directory name if it succeeds, boolean false otherwise
author:  Hugues Peeters <hugues.peeters@claroline.net>
author:  Bert Vanderkimpen


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  
[ Top ]



dir_total_space [line 568]

- dir_total_space( - $dirPath)

Compute the size already occupied by a directory and is subdirectories



Tags:

return:  int - return the directory size in bytes
author:  - Hugues Peeters <peeters@ipm.ucl.ac.be>


Parameters

-   $dirPath   dirPath (string) - size of the file in byte
[ Top ]



disable_dangerous_file [line 158]

string disable_dangerous_file( string $filename)

this function executes our safety precautions more functions can be added



Tags:

see:  htaccess2txt()
see:  php2phps()


Parameters

string   $filename  
[ Top ]



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:

return:  total size
author:  Bert vanderkimpen


Parameters

int   $to_group_id   (to calculate group document space)
[ Top ]



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:

return:  boolean true if there is enough space, boolean false otherwise
author:  - Hugues Peeters <peeters@ipm.ucl.ac.be>
see:  - enough_size() uses dir_total_space() function
deprecated:  use enough_space instead!


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
[ Top ]



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:

return:  true if there is enough space, false otherwise
author:  Bert Vanderkimpen
see:  enough_space() uses documents_total_space() function


Parameters

array   $_course  
int   2   max_dir_space maximum size
int   $file_size   file_size size of the file in byte
   $max_dir_space  
[ Top ]



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:

return:  0 to skip file, 1 to keep file


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')
[ Top ]



get_document_title [line 196]

name get_document_title( string $name)

Returns the name without extension, used for the title



Tags:

return:  without the extension


Parameters

string   $name  
[ Top ]



get_levels [line 1294]

The get_levels( path+filename $filename)

Returns the directory depth of the file.



Tags:

return:  directory depth
author:  Olivier Cauberghe <olivier.cauberghe@ugent.be>


Parameters

path+filename   $filename   eg: /main/document/document.php
[ Top ]



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:

return:  of the saved file


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  
[ Top ]



htaccess2txt [line 139]

string htaccess2txt( string $filename)

Renames .htaccess & .HTACCESS tot htaccess.txt



Parameters

string   $filename  
[ Top ]



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  
[ Top ]



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:

author:  Hugues Peeters <hugues.peeters@claroline.net>
author:  Bert Vanderkimpen


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  
[ Top ]



php2phps [line 125]

- php2phps( - $fileName)

change the file name extension from .php to .phps Useful to secure a site !!



Tags:

return:  the filenam phps'ized
author:  - Hugues Peeters <peeters@ipm.ucl.ac.be>


Parameters

-   $fileName   fileName (string) name of a file
[ Top ]



process_uploaded_file [line 214]

true process_uploaded_file( array $uploaded_file)

This checks if the upload succeeded



Tags:

return:  if upload succeeded


Parameters

array   $uploaded_file   ($_FILES)
[ Top ]



remove_accents [line 1926]

void remove_accents( $string)



Parameters

   $string  
[ Top ]



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 (&ocirc;, @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 &nbsp; and &lt;, 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:

return:  The escaped string, not absolutely correct but satisfying


Parameters

string   $string   The accentuated string
[ Top ]



replace_dangerous_char [line 86]

- replace_dangerous_char( - $filename, [- $strict = 'loose'])

replaces "forbidden" characters in a filename string



Tags:

return:  the cleaned filename
author:  - Hugues Peeters <peeters@ipm.ucl.ac.be>
author:  - Ren� Haentjens, UGent (RH)


Parameters

-   $filename   string $filename
-   $strict   string $strict (optional) remove all non-ASCII
[ Top ]



replace_img_path_in_html_file [line 1498]

void replace_img_path_in_html_file( $originalImgPath, $newImgPath, $htmlFile)



Parameters

   $originalImgPath  
   $newImgPath  
   $htmlFile  
[ Top ]



search_img_from_html [line 1368]

array search_img_from_html( string $htmlFile)

retrieve the image path list in a html file



Tags:

return:  - images path list
author:  Hugues Peeters <hugues.peeters@claroline.net>


Parameters

string   $htmlFile  
[ Top ]



set_default_settings [line 1318]

void set_default_settings( path,filename $upload_path, $filename, [ $filetype = &quot;file&quot;])

Adds file to document table in database



Tags:

author:  Olivier Cauberghe <olivier.cauberghe@ugent.be>


Parameters

path,filename   $upload_path  
   $filename  
   $filetype  
[ Top ]



treat_uploaded_file [line 739]

boolean treat_uploaded_file( array $uploadedFile, string $baseWorkDir, string $uploadPath, int $maxFilledSpace, [ $uncompress = ''])



Tags:

return:  true if it succeds, false otherwise
author:  Hugues Peeters <hugues.peeters@claroline.net>


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  
[ Top ]



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:

return:  unique name


Parameters

string   $path  
string   $name  
[ Top ]



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:

return:  true if it succeeds false otherwise
author:  Hugues Peeters <hugues.peeters@claroline.net>
author:  Bert Vanderkimpen


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  
[ Top ]



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:

return:  true if it succeeds false otherwise
author:  Hugues Peeters <hugues.peeters@claroline.net>


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
[ Top ]



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:

return:  true /false


Parameters

array   $_course  
int   $document_id  
int   $filesize  
int   $readonly  
[ Top ]



Documentation generated on Thu, 12 Jun 2008 13:29:04 -0500 by phpDocumentor 1.4.1