|
|
|
|
@@ -23,8 +23,9 @@
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return user/group account of web server
|
|
|
|
|
* @param $mode 'user' or 'group'
|
|
|
|
|
* @return string
|
|
|
|
|
*
|
|
|
|
|
* @param string $mode 'user' or 'group'
|
|
|
|
|
* @return string Return user or group of web server
|
|
|
|
|
*/
|
|
|
|
|
function dol_getwebuser($mode)
|
|
|
|
|
{
|
|
|
|
|
@@ -37,14 +38,15 @@ function dol_getwebuser($mode)
|
|
|
|
|
/**
|
|
|
|
|
* Scan a directory and return a list of files/directories.
|
|
|
|
|
* Content for string is UTF8 and dir separator is "/".
|
|
|
|
|
* @param $path Starting path from which to search
|
|
|
|
|
* @param $types Can be "directories", "files", or "all"
|
|
|
|
|
* @param $recursive Determines whether subdirectories are searched
|
|
|
|
|
* @param $filter Regex for include filter
|
|
|
|
|
* @param $excludefilter Array of Regex for exclude filter (example: array('\.meta$','^\.')
|
|
|
|
|
* @param $sortcriteria Sort criteria ("","name","date","size")
|
|
|
|
|
* @param $sortorder Sort order (SORT_ASC, SORT_DESC)
|
|
|
|
|
* @param $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
|
|
|
|
|
*
|
|
|
|
|
* @param string $path Starting path from which to search
|
|
|
|
|
* @param string $types Can be "directories", "files", or "all"
|
|
|
|
|
* @param int $recursive Determines whether subdirectories are searched
|
|
|
|
|
* @param string $filter Regex for include filter
|
|
|
|
|
* @param string $excludefilter Array of Regex for exclude filter (example: array('\.meta$','^\.')
|
|
|
|
|
* @param string $sortcriteria Sort criteria ("","name","date","size")
|
|
|
|
|
* @param string $sortorder Sort order (SORT_ASC, SORT_DESC)
|
|
|
|
|
* @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
|
|
|
|
|
* @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file')
|
|
|
|
|
*/
|
|
|
|
|
function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0)
|
|
|
|
|
@@ -152,8 +154,9 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fast compare of 2 files identified by their properties ->name, ->date and ->size
|
|
|
|
|
* @param $a File 1
|
|
|
|
|
* @param $b File 2
|
|
|
|
|
*
|
|
|
|
|
* @param string $a File 1
|
|
|
|
|
* @param string $b File 2
|
|
|
|
|
* @return int 1, 0, 1
|
|
|
|
|
*/
|
|
|
|
|
function dol_compare_file($a, $b)
|
|
|
|
|
@@ -186,11 +189,10 @@ function dol_compare_file($a, $b)
|
|
|
|
|
/**
|
|
|
|
|
* Return mime type of a file
|
|
|
|
|
*
|
|
|
|
|
* @param file Filename we looking for MIME type
|
|
|
|
|
* @param default Default mime type if extension not found in known list
|
|
|
|
|
* @param mode 0=Return full mime, 1=otherwise short mime string, 2=image for mime type, 3=source language
|
|
|
|
|
* @return string Return a mime type family
|
|
|
|
|
* (text/xxx, application/xxx, image/xxx, audio, video, archive)
|
|
|
|
|
* @param string $file Filename we looking for MIME type
|
|
|
|
|
* @param string $default Default mime type if extension not found in known list
|
|
|
|
|
* @param int $mode 0=Return full mime, 1=otherwise short mime string, 2=image for mime type, 3=source language
|
|
|
|
|
* @return string Return a mime type family (text/xxx, application/xxx, image/xxx, audio, video, archive)
|
|
|
|
|
* @see image_format_supported (images.lib.php)
|
|
|
|
|
*/
|
|
|
|
|
function dol_mimetype($file,$default='application/octet-stream',$mode=0)
|
|
|
|
|
@@ -297,7 +299,7 @@ function dol_mimetype($file,$default='application/octet-stream',$mode=0)
|
|
|
|
|
/**
|
|
|
|
|
* Test if filename is a directory
|
|
|
|
|
*
|
|
|
|
|
* @param folder Name of folder
|
|
|
|
|
* @param string $folder Name of folder
|
|
|
|
|
* @return boolean True if it's a directory, False if not found
|
|
|
|
|
*/
|
|
|
|
|
function dol_is_dir($folder)
|
|
|
|
|
@@ -310,7 +312,7 @@ function dol_is_dir($folder)
|
|
|
|
|
/**
|
|
|
|
|
* Return if path is a file
|
|
|
|
|
*
|
|
|
|
|
* @param $pathoffile
|
|
|
|
|
* @param string $pathoffile Path of file
|
|
|
|
|
* @return boolean True or false
|
|
|
|
|
*/
|
|
|
|
|
function dol_is_file($pathoffile)
|
|
|
|
|
@@ -322,7 +324,7 @@ function dol_is_file($pathoffile)
|
|
|
|
|
/**
|
|
|
|
|
* Return if path is an URL
|
|
|
|
|
*
|
|
|
|
|
* @param $url
|
|
|
|
|
* @param string $url Url
|
|
|
|
|
* @return boolean True or false
|
|
|
|
|
*/
|
|
|
|
|
function dol_is_url($url)
|
|
|
|
|
@@ -339,7 +341,7 @@ function dol_is_url($url)
|
|
|
|
|
/**
|
|
|
|
|
* Test if a folder is empty
|
|
|
|
|
*
|
|
|
|
|
* @param folder Name of folder
|
|
|
|
|
* @param string $folder Name of folder
|
|
|
|
|
* @return boolean True if dir is empty or non-existing, False if it contains files
|
|
|
|
|
*/
|
|
|
|
|
function dol_dir_is_emtpy($folder)
|
|
|
|
|
@@ -365,7 +367,8 @@ function dol_dir_is_emtpy($folder)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Count number of lines in a file
|
|
|
|
|
* @param file Filename
|
|
|
|
|
*
|
|
|
|
|
* @param string $file Filename
|
|
|
|
|
* @return int <0 if KO, Number of lines in files if OK
|
|
|
|
|
*/
|
|
|
|
|
function dol_count_nb_of_line($file)
|
|
|
|
|
@@ -395,7 +398,8 @@ function dol_count_nb_of_line($file)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return size of a file
|
|
|
|
|
* @param $pathoffile
|
|
|
|
|
*
|
|
|
|
|
* @param tring $pathoffile Path of file
|
|
|
|
|
* @return string File size
|
|
|
|
|
*/
|
|
|
|
|
function dol_filesize($pathoffile)
|
|
|
|
|
@@ -406,7 +410,8 @@ function dol_filesize($pathoffile)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return time of a file
|
|
|
|
|
* @param $pathoffile
|
|
|
|
|
*
|
|
|
|
|
* @param string $pathoffile Path of file
|
|
|
|
|
* @return timestamp Time of file
|
|
|
|
|
*/
|
|
|
|
|
function dol_filemtime($pathoffile)
|
|
|
|
|
@@ -446,10 +451,11 @@ function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Move a file into another name
|
|
|
|
|
* @param $srcfile Source file (can't be a directory)
|
|
|
|
|
* @param $destfile Destination file (can't be a directory)
|
|
|
|
|
* @param $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK)
|
|
|
|
|
* @param $overwriteifexists Overwrite file if exists (1 by default)
|
|
|
|
|
*
|
|
|
|
|
* @param string $srcfile Source file (can't be a directory)
|
|
|
|
|
* @param string $destfile Destination file (can't be a directory)
|
|
|
|
|
* @param string $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK)
|
|
|
|
|
* @param int $overwriteifexists Overwrite file if exists (1 by default)
|
|
|
|
|
* @return boolean True if OK, false if KO
|
|
|
|
|
*/
|
|
|
|
|
function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
|
|
|
|
|
@@ -475,12 +481,13 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
|
|
|
|
|
/**
|
|
|
|
|
* Move an uploaded file after some controls.
|
|
|
|
|
* If there is errors (virus found, antivir in error, bad filename), file is not moved.
|
|
|
|
|
* @param src_file Source full path filename ($_FILES['field']['tmp_name'])
|
|
|
|
|
* @param dest_file Target full path filename
|
|
|
|
|
* @param allowoverwrite 1=Overwrite target file if it already exists
|
|
|
|
|
* @param disablevirusscan 1=Disable virus scan
|
|
|
|
|
* @param uploaderrorcode Value of upload error code ($_FILES['field']['error'])
|
|
|
|
|
* @param notrigger Disable all triggers
|
|
|
|
|
*
|
|
|
|
|
* @param string $src_file Source full path filename ($_FILES['field']['tmp_name'])
|
|
|
|
|
* @param string $dest_file Target full path filename
|
|
|
|
|
* @param int $allowoverwrite 1=Overwrite target file if it already exists
|
|
|
|
|
* @param int $disablevirusscan 1=Disable virus scan
|
|
|
|
|
* @param string $uploaderrorcode Value of upload error code ($_FILES['field']['error'])
|
|
|
|
|
* @param int $notrigger Disable all triggers
|
|
|
|
|
* @return int >0 if OK, <0 or string if KO
|
|
|
|
|
*/
|
|
|
|
|
function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $notrigger=0)
|
|
|
|
|
@@ -606,15 +613,14 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
|
|
|
|
|
/**
|
|
|
|
|
* Remove a file or several files with a mask
|
|
|
|
|
*
|
|
|
|
|
* @param file File to delete or mask of file to delete
|
|
|
|
|
* @param disableglob Disable usage of glob like *
|
|
|
|
|
* @param nophperrors Disable all PHP output errors
|
|
|
|
|
* @param notrigger Disable all triggers
|
|
|
|
|
* @param triggercode Code of trigger TODO ???? why ?
|
|
|
|
|
* @param object Object for trigger
|
|
|
|
|
* @param string $file File to delete or mask of file to delete
|
|
|
|
|
* @param int $disableglob Disable usage of glob like *
|
|
|
|
|
* @param int $nophperrors Disable all PHP output errors
|
|
|
|
|
* @param int $notrigger Disable all triggers
|
|
|
|
|
* @param Object $object Object
|
|
|
|
|
* @return boolean True if file is deleted, False if error
|
|
|
|
|
*/
|
|
|
|
|
function dol_delete_file($file,$disableglob=0,$nophperrors=0,$notrigger=0,$triggercode='FILE_DELETE',$object=null)
|
|
|
|
|
function dol_delete_file($file,$disableglob=0,$nophperrors=0,$notrigger=0,$object=null)
|
|
|
|
|
{
|
|
|
|
|
global $db, $conf, $user, $langs;
|
|
|
|
|
|
|
|
|
|
@@ -635,10 +641,11 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$notrigger=0,$trigg
|
|
|
|
|
if (! is_object($object)) $object=(object) 'dummy';
|
|
|
|
|
$object->src_file=$file;
|
|
|
|
|
|
|
|
|
|
// TODO Replace trigger by a hook. Triggers must be used for business events only.
|
|
|
|
|
// Appel des triggers
|
|
|
|
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
|
|
|
|
$interface=new Interfaces($db);
|
|
|
|
|
$result=$interface->run_triggers($triggercode,$object,$user,$langs,$conf);
|
|
|
|
|
$result=$interface->run_triggers('FILE_DELETE',$object,$user,$langs,$conf);
|
|
|
|
|
if ($result < 0) { $error++; $errors=$interface->errors; }
|
|
|
|
|
// Fin appel triggers
|
|
|
|
|
}
|
|
|
|
|
@@ -660,8 +667,8 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$notrigger=0,$trigg
|
|
|
|
|
* Remove a directory (not recursive, so content must be empty).
|
|
|
|
|
* If directory is not empty, return false
|
|
|
|
|
*
|
|
|
|
|
* @param dir Directory to delete
|
|
|
|
|
* @param nophperrors Disable all PHP output errors
|
|
|
|
|
* @param string $dir Directory to delete
|
|
|
|
|
* @param int $nophperrors Disable all PHP output errors
|
|
|
|
|
* @return boolean True if success, false if error
|
|
|
|
|
*/
|
|
|
|
|
function dol_delete_dir($dir,$nophperrors=0)
|
|
|
|
|
@@ -886,9 +893,10 @@ function dol_add_file_process($upload_dir,$allowoverwrite=0,$donotupdatesession=
|
|
|
|
|
/**
|
|
|
|
|
* Remove an uploaded file (for example after submitting a new file a mail form).
|
|
|
|
|
* All information used are in db, conf, langs, user and _FILES.
|
|
|
|
|
* @param filenb File nb to delete
|
|
|
|
|
* @param donotupdatesession 1=Do not edit _SESSION variable
|
|
|
|
|
* @param donotdeletefile 1=Do not delete physically file
|
|
|
|
|
*
|
|
|
|
|
* @param int $filenb File nb to delete
|
|
|
|
|
* @param int $donotupdatesession 1=Do not edit _SESSION variable
|
|
|
|
|
* @param int $donotdeletefile 1=Do not delete physically file
|
|
|
|
|
* @return string Message with result of upload and store.
|
|
|
|
|
*/
|
|
|
|
|
function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=0)
|
|
|
|
|
|