38 return preg_replace(
'/^.*\/([^\/]+)$/',
'$1', rtrim($pathfile,
'/'));
61 function dol_dir_list($path, $types =
"all", $recursive = 0, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename =
"", $donotfollowsymlinks = 0, $nbsecondsold = 0)
63 global $db, $hookmanager;
66 if ($recursive <= 1) {
67 dol_syslog(
"files.lib.php::dol_dir_list path=".$path.
" types=".$types.
" recursive=".$recursive.
" filter=".$filter.
" excludefilter=".json_encode($excludefilter));
71 $loaddate = ($mode == 1 || $mode == 2 || $nbsecondsold) ?
true :
false;
72 $loadsize = ($mode == 1 || $mode == 3) ?
true :
false;
73 $loadperm = ($mode == 1 || $mode == 4) ?
true :
false;
76 $path = preg_replace(
'/([\\/]+)$/i',
'', $path);
83 if (is_object($hookmanager) && !$nohook) {
84 $hookmanager->resArray = array();
86 $hookmanager->initHooks(array(
'fileslib'));
91 'recursive' => $recursive,
93 'excludefilter' => $excludefilter,
94 'sortcriteria' => $sortcriteria,
95 'sortorder' => $sortorder,
96 'loaddate' => $loaddate,
97 'loadsize' => $loadsize,
100 $reshook = $hookmanager->executeHooks(
'getDirList', $parameters, $object);
104 if (empty($reshook)) {
105 if (!is_dir($newpath)) {
109 if ($dir = opendir($newpath)) {
113 while (
false !== ($file = readdir($dir))) {
115 $file = utf8_encode($file);
117 $fullpathfile = ($newpath ? $newpath.
'/' :
'').$file;
122 $excludefilterarray = array(
'^\.');
123 if (is_array($excludefilter)) {
124 $excludefilterarray = array_merge($excludefilterarray, $excludefilter);
125 } elseif ($excludefilter) {
126 $excludefilterarray[] = $excludefilter;
129 foreach ($excludefilterarray as $filt) {
130 if (preg_match(
'/'.$filt.
'/i', $file) || preg_match(
'/'.$filt.
'/i', $fullpathfile)) {
140 if ($isdir && (($types ==
"directories") || ($types ==
"all") || $recursive > 0)) {
142 if (($types ==
"directories") || ($types ==
"all")) {
143 if ($loaddate || $sortcriteria ==
'date') {
146 if ($loadsize || $sortcriteria ==
'size') {
149 if ($loadperm || $sortcriteria ==
'perm') {
153 if (!$filter || preg_match(
'/'.$filter.
'/i', $file)) {
155 preg_match(
'/([^\/]+)\/[^\/]+$/', $path.
'/'.$file, $reg);
156 $level1name = (isset($reg[1]) ? $reg[1] :
'');
157 $file_list[] = array(
160 "level1name" => $level1name,
161 "relativename" => ($relativename ? $relativename.
'/' :
'').$file,
162 "fullname" => $path.
'/'.$file,
172 if ($recursive > 0) {
173 if (empty($donotfollowsymlinks) || !is_link($path.
"/".$file)) {
175 $file_list = array_merge($file_list,
dol_dir_list($path.
"/".$file, $types, $recursive + 1, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename !=
'' ? $relativename.
'/' :
'').$file, $donotfollowsymlinks, $nbsecondsold));
178 } elseif (!$isdir && (($types ==
"files") || ($types ==
"all"))) {
180 if ($loaddate || $sortcriteria ==
'date') {
183 if ($loadsize || $sortcriteria ==
'size') {
187 if (!$filter || preg_match(
'/'.$filter.
'/i', $file)) {
188 if (empty($nbsecondsold) || $filedate <= ($now - $nbsecondsold)) {
189 preg_match(
'/([^\/]+)\/[^\/]+$/', $path.
'/'.$file, $reg);
190 $level1name = (isset($reg[1]) ? $reg[1] :
'');
191 $file_list[] = array(
194 "level1name" => $level1name,
195 "relativename" => ($relativename ? $relativename.
'/' :
'').$file,
196 "fullname" => $path.
'/'.$file,
209 if (!empty($sortcriteria) && $sortorder) {
210 $file_list =
dol_sort_array($file_list, $sortcriteria, ($sortorder == SORT_ASC ?
'asc' :
'desc'));
215 if (is_object($hookmanager) && is_array($hookmanager->resArray)) {
216 $file_list = array_merge($file_list, $hookmanager->resArray);
236 function dol_dir_list_in_database($path, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0)
240 $sql =
" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams,";
241 $sql .=
" date_c, tms as date_m, fk_user_c, fk_user_m, acl, position, share";
243 $sql .=
", description";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_files";
246 $sql .=
" WHERE entity = ".$conf->entity;
247 if (preg_match(
'/%$/', $path)) {
248 $sql .=
" AND filepath LIKE '".$db->escape($path).
"'";
250 $sql .=
" AND filepath = '".$db->escape($path).
"'";
253 $resql = $db->query(
$sql);
255 $file_list = array();
256 $num = $db->num_rows($resql);
259 $obj = $db->fetch_object($resql);
262 preg_match(
'/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename, $reg);
263 $level1name = (isset($reg[1]) ? $reg[1] :
'');
264 $file_list[] = array(
265 "rowid" => $obj->rowid,
266 "label" => $obj->label,
267 "name" => $obj->filename,
268 "path" => DOL_DATA_ROOT.
'/'.$obj->filepath,
269 "level1name" => $level1name,
270 "fullname" => DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename,
271 "fullpath_orig" => $obj->fullpath_orig,
272 "date_c" => $db->jdate($obj->date_c),
273 "date_m" => $db->jdate($obj->date_m),
275 "keywords" => $obj->keywords,
276 "cover" => $obj->cover,
277 "position" => (
int) $obj->position,
279 "share" => $obj->share,
280 "description" => ($mode ? $obj->description :
'')
287 if (!empty($sortcriteria)) {
289 foreach ($file_list as $key => $row) {
290 $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] :
'');
294 array_multisort($myarray, $sortorder, $file_list);
316 global $conf, $db, $user;
322 if ($modulepart ==
'produit' &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
324 if (!empty($object->id)) {
326 $upload_dirold = $conf->product->multidir_output[$object->entity].
'/'.substr(substr(
"000".$object->id, -2), 1, 1).
'/'.substr(substr(
"000".$object->id, -2), 0, 1).
'/'.$object->id.
"/photos";
328 $upload_dirold = $conf->service->multidir_output[$object->entity].
'/'.substr(substr(
"000".$object->id, -2), 1, 1).
'/'.substr(substr(
"000".$object->id, -2), 0, 1).
'/'.$object->id.
"/photos";
331 $relativedirold = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dirold);
332 $relativedirold = preg_replace(
'/^[\\/]/',
'', $relativedirold);
334 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($relativedirold,
'',
null,
'name', SORT_ASC));
343 foreach ($filearray as $key => $val) {
344 $tmpfilename = preg_replace(
'/\.noexe$/',
'', $filearray[$key][
'name']);
347 foreach ($filearrayindatabase as $key2 => $val2) {
348 if (($filearrayindatabase[$key2][
'path'] == $filearray[$key][
'path']) && ($filearrayindatabase[$key2][
'name'] == $tmpfilename)) {
349 $filearray[$key][
'position_name'] = ($filearrayindatabase[$key2][
'position'] ? $filearrayindatabase[$key2][
'position'] :
'0').
'_'.$filearrayindatabase[$key2][
'name'];
350 $filearray[$key][
'position'] = $filearrayindatabase[$key2][
'position'];
351 $filearray[$key][
'cover'] = $filearrayindatabase[$key2][
'cover'];
352 $filearray[$key][
'keywords'] = $filearrayindatabase[$key2][
'keywords'];
353 $filearray[$key][
'acl'] = $filearrayindatabase[$key2][
'acl'];
354 $filearray[$key][
'rowid'] = $filearrayindatabase[$key2][
'rowid'];
355 $filearray[$key][
'label'] = $filearrayindatabase[$key2][
'label'];
356 $filearray[$key][
'share'] = $filearrayindatabase[$key2][
'share'];
363 $filearray[$key][
'position'] =
'999999';
364 $filearray[$key][
'cover'] = 0;
365 $filearray[$key][
'acl'] =
'';
367 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'fullname']);
369 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) {
370 dol_syslog(
"list_of_documents We found a file called '".$filearray[$key][
'name'].
"' not indexed into database. We add it");
371 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
375 $filename = basename($rel_filename);
376 $rel_dir = dirname($rel_filename);
377 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
378 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
380 $ecmfile->filepath = $rel_dir;
381 $ecmfile->filename = $filename;
382 $ecmfile->label = md5_file(
dol_osencode($filearray[$key][
'fullname']));
383 $ecmfile->fullpath_orig = $filearray[$key][
'fullname'];
384 $ecmfile->gen_or_uploaded =
'unknown';
385 $ecmfile->description =
'';
386 $ecmfile->keywords =
'';
387 $result = $ecmfile->create($user);
391 $filearray[$key][
'rowid'] = $result;
394 $filearray[$key][
'rowid'] = 0;
414 $sortorder = strtoupper($sortorder);
416 if ($sortorder ==
'ASC') {
424 if ($sortfield ==
'name') {
425 if ($a->name == $b->name) {
428 return ($a->name < $b->name) ? $retup : $retdown;
430 if ($sortfield ==
'date') {
431 if ($a->date == $b->date) {
434 return ($a->date < $b->date) ? $retup : $retdown;
436 if ($sortfield ==
'size') {
437 if ($a->size == $b->size) {
440 return ($a->size < $b->size) ? $retup : $retdown;
454 if (is_dir($newfolder)) {
469 if (!is_readable($dir)) {
472 return (count(scandir($dir)) == 2);
484 return is_file($newpathoffile);
496 return is_link($newpathoffile);
507 $tmpprot = array(
'file',
'http',
'https',
'ftp',
'zlib',
'data',
'ssh',
'ssh2',
'ogg',
'expect');
508 foreach ($tmpprot as $prot) {
509 if (preg_match(
'/^'.$prot.
':/i', $url)) {
525 if (is_dir($newfolder)) {
526 $handle = opendir($newfolder);
527 $folder_content =
'';
528 while ((gettype($name = readdir($handle)) !=
"boolean")) {
529 $name_array[] = $name;
531 foreach ($name_array as $temp) {
532 $folder_content .= $temp;
537 if ($folder_content ==
"...") {
560 $fp = fopen($newfile,
'r');
565 if (!$line ===
false) {
588 return filesize($newpathoffile);
600 return @filemtime($newpathoffile);
612 return fileperms($newpathoffile);
627 function dolReplaceInFile($srcfile, $arrayreplacement, $destfile =
'', $newmask = 0, $indexdatabase = 0, $arrayreplacementisregex = 0)
631 dol_syslog(
"files.lib.php::dolReplaceInFile srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" indexdatabase=".$indexdatabase.
" arrayreplacementisregex=".$arrayreplacementisregex);
633 if (empty($srcfile)) {
636 if (empty($destfile)) {
637 $destfile = $srcfile;
641 if (($destfile != $srcfile) && $destexists) {
647 dol_syslog(
"files.lib.php::dolReplaceInFile failed to read src file", LOG_WARNING);
651 $tmpdestfile = $destfile.
'.tmp';
656 $newdirdestfile = dirname($newpathofdestfile);
658 if ($destexists && !is_writable($newpathofdestfile)) {
659 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
662 if (!is_writable($newdirdestfile)) {
663 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
670 $content = file_get_contents($newpathofsrcfile,
'r');
672 if (empty($arrayreplacementisregex)) {
675 foreach ($arrayreplacement as $key => $value) {
676 $content = preg_replace($key, $value, $content);
680 file_put_contents($newpathoftmpdestfile, $content);
681 dolChmod($newpathoftmpdestfile, $newmask);
684 $result =
dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
686 dol_syslog(
"files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
689 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
690 $newmask = $conf->global->MAIN_UMASK;
692 if (empty($newmask)) {
693 dol_syslog(
"Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
697 dolChmod($newpathofdestfile, $newmask);
713 function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
717 dol_syslog(
"files.lib.php::dol_copy srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
719 if (empty($srcfile) || empty($destfile)) {
724 if (!$overwriteifexists && $destexists) {
730 $newdirdestfile = dirname($newpathofdestfile);
732 if ($destexists && !is_writable($newpathofdestfile)) {
733 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
736 if (!is_writable($newdirdestfile)) {
737 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
741 $result = @copy($newpathofsrcfile, $newpathofdestfile);
744 dol_syslog(
"files.lib.php::dol_copy failed to copy", LOG_WARNING);
747 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
748 $newmask = $conf->global->MAIN_UMASK;
750 if (empty($newmask)) {
751 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
755 dolChmod($newpathofdestfile, $newmask);
773 function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement =
null, $excludesubdir = 0, $excludefileext =
null)
779 dol_syslog(
"files.lib.php::dolCopyDir srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
781 if (empty($srcfile) || empty($destfile)) {
791 $dirmaskdec = octdec($newmask);
792 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
793 $dirmaskdec = octdec($conf->global->MAIN_UMASK);
795 $dirmaskdec |= octdec(
'0200');
796 dol_mkdir($destfile,
'', decoct($dirmaskdec));
803 if (is_dir($ossrcfile)) {
804 $dir_handle = opendir($ossrcfile);
805 while ($file = readdir($dir_handle)) {
806 if ($file !=
"." && $file !=
".." && !is_link($ossrcfile.
"/".$file)) {
807 if (is_dir($ossrcfile.
"/".$file)) {
808 if (empty($excludesubdir) || ($excludesubdir == 2 && strlen($file) == 2)) {
811 if (is_array($arrayreplacement)) {
812 foreach ($arrayreplacement as $key => $val) {
813 $newfile = str_replace($key, $val, $newfile);
817 $tmpresult =
dolCopyDir($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists, $arrayreplacement, $excludesubdir, $excludefileext);
822 if (is_array($excludefileext)) {
823 $extension = pathinfo($file, PATHINFO_EXTENSION);
824 if (in_array($extension, $excludefileext)) {
831 if (is_array($arrayreplacement)) {
832 foreach ($arrayreplacement as $key => $val) {
833 $newfile = str_replace($key, $val, $newfile);
836 $tmpresult =
dol_copy($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists);
839 if ($result > 0 && $tmpresult >= 0) {
842 $result = $tmpresult;
849 closedir($dir_handle);
875 function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
877 global $user, $db, $conf;
880 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
885 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
889 if ($overwriteifexists || !$destexists) {
894 $testvirusarray = array();
897 if (count($testvirusarray)) {
898 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
903 global $dolibarr_main_restrict_os_commands;
904 if (!empty($dolibarr_main_restrict_os_commands)) {
905 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
906 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
907 if (in_array(basename($destfile), $arrayofallowedcommand)) {
910 dol_syslog(
"files.lib.php::dol_move canceled because target filename ".basename($destfile).
" is using a reserved command name. we ignore the move request.", LOG_WARNING);
915 $result = @rename($newpathofsrcfile, $newpathofdestfile);
918 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
921 $result = @rename($newpathofsrcfile, $newpathofdestfile);
923 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
928 if ($result && $indexdatabase) {
930 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
931 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
932 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
933 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
934 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
937 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
938 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
941 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
942 if ($resultecmtarget > 0) {
943 $ecmfiletarget->delete($user);
947 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
948 if ($resultecm > 0) {
949 $filename = basename($rel_filetorenameafter);
950 $rel_dir = dirname($rel_filetorenameafter);
951 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
952 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
954 $ecmfile->filepath = $rel_dir;
955 $ecmfile->filename = $filename;
957 $resultecm = $ecmfile->update($user);
958 } elseif ($resultecm == 0) {
959 $filename = basename($rel_filetorenameafter);
960 $rel_dir = dirname($rel_filetorenameafter);
961 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
962 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
964 $ecmfile->filepath = $rel_dir;
965 $ecmfile->filename = $filename;
967 $ecmfile->fullpath_orig = $srcfile;
968 $ecmfile->gen_or_uploaded =
'unknown';
969 $ecmfile->description =
'';
970 $ecmfile->keywords =
'';
971 $resultecm = $ecmfile->create($user);
972 if ($resultecm < 0) {
975 } elseif ($resultecm < 0) {
979 if ($resultecm > 0) {
987 if (empty($newmask)) {
988 $newmask = empty($conf->global->MAIN_UMASK) ?
'0755' : $conf->global->MAIN_UMASK;
994 dolChmod($newpathofdestfile, $newmask);
1011 function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
1014 global $user, $db, $conf;
1017 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
1019 $srcbasename = basename($srcdir);
1023 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. we ignore the move request.");
1027 if ($overwriteifexists || !$destexists) {
1031 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1033 if ($result && $renamedircontent) {
1034 if (file_exists($newpathofdestdir)) {
1035 $destbasename = basename($newpathofdestdir);
1037 if (!empty($files) && is_array($files)) {
1038 foreach ($files as $key => $file) {
1039 if (!file_exists($file[
"fullname"]))
continue;
1040 $filepath = $file[
"path"];
1041 $oldname = $file[
"name"];
1043 $newname = str_replace($srcbasename, $destbasename, $oldname);
1044 if (!empty($newname) && $newname !== $oldname) {
1045 if ($file[
"type"] ==
"dir") {
1046 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1048 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname);
1075 return trim(basename($filename),
".\x00..\x20");
1089 if (!empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) {
1090 if (!class_exists(
'AntiVir')) {
1091 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1094 $result = $antivir->dol_avscan_file($src_file);
1096 $reterrors = $antivir->errors;
1124 function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1126 global $conf, $db, $user, $langs;
1127 global $object, $hookmanager;
1130 $file_name = $dest_file;
1133 if (empty($nohook)) {
1134 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1136 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1137 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters, $object);
1140 if (empty($reshook)) {
1142 if ($uploaderrorcode) {
1143 switch ($uploaderrorcode) {
1144 case UPLOAD_ERR_INI_SIZE:
1145 return 'ErrorFileSizeTooLarge';
1146 case UPLOAD_ERR_FORM_SIZE:
1147 return 'ErrorFileSizeTooLarge';
1148 case UPLOAD_ERR_PARTIAL:
1149 return 'ErrorPartialFile';
1150 case UPLOAD_ERR_NO_TMP_DIR:
1151 return 'ErrorNoTmpDir';
1152 case UPLOAD_ERR_CANT_WRITE:
1153 return 'ErrorFailedToWriteInDir';
1154 case UPLOAD_ERR_EXTENSION:
1155 return 'ErrorUploadBlockedByAddon';
1162 if (empty($disablevirusscan) && file_exists($src_file)) {
1164 if (count($checkvirusarray)) {
1165 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.join(
',', $checkvirusarray), LOG_WARNING);
1166 return 'ErrorFileIsInfectedWithAVirus: '.join(
',', $checkvirusarray);
1175 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
1176 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1177 $publicmediasdirwithslash .=
'/';
1180 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
1181 $file_name .=
'.noexe';
1188 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1189 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1195 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1196 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1202 $errmsg = join(
',', $hookmanager->errors);
1203 if (empty($errmsg)) {
1204 $errmsg =
'ErrorReturnedBySomeHooks';
1207 } elseif (empty($reshook)) {
1213 if (!is_writable(dirname($file_name_osencoded))) {
1214 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1215 return 'ErrorDirNotWritable';
1219 if (!$allowoverwrite) {
1220 if (file_exists($file_name_osencoded)) {
1221 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1222 return 'ErrorFileAlreadyExists';
1225 if (is_dir($file_name_osencoded)) {
1226 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1227 return 'ErrorDirWithFileNameAlreadyExists';
1232 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1235 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
1236 return $successcode;
1238 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1243 return $successcode;
1261 function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object =
null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1263 global $db, $conf, $user, $langs;
1264 global $hookmanager;
1267 $langs->loadLangs(array(
'other',
'errors'));
1269 if (empty($nolog)) {
1270 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1275 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1276 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1281 if (empty($nohook)) {
1282 $hookmanager->initHooks(array(
'fileslib'));
1284 $parameters = array(
1286 'disableglob'=> $disableglob,
1287 'nophperrors' => $nophperrors
1289 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters, $object);
1292 if (empty($nohook) && $reshook != 0) {
1300 if (empty($disableglob) && !empty($file_osencoded)) {
1302 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1303 $globencoded = str_replace(
']',
'\]', $globencoded);
1304 $listofdir = glob($globencoded);
1305 if (!empty($listofdir) && is_array($listofdir)) {
1306 foreach ($listofdir as $filename) {
1308 $ok = @unlink($filename);
1310 $ok = unlink($filename);
1314 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1315 dol_syslog(
"Error in deletion, but parent directory exists with no permission to write, we try to change permission on parent directory and retry...", LOG_DEBUG);
1316 dolChmod(dirname($filename), decoct(fileperms(dirname($filename)) | 0200));
1319 $ok = @unlink($filename);
1321 $ok = unlink($filename);
1326 if (empty($nolog)) {
1327 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1331 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1332 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1333 if (is_object($db) && $indexdatabase) {
1334 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1335 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1337 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1338 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1340 $result = $ecmfile->fetch(0,
'', $rel_filetodelete);
1341 if ($result >= 0 && $ecmfile->id > 0) {
1342 $result = $ecmfile->delete($user);
1350 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1356 dol_syslog(
"No files to delete found", LOG_DEBUG);
1361 $ok = @unlink($file_osencoded);
1363 $ok = unlink($file_osencoded);
1366 if (empty($nolog)) {
1367 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1370 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1391 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1392 dol_syslog(
"Refused to delete dir ".$dir.
' (contains invalid char sequence)', LOG_WARNING);
1397 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1412 function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0)
1414 if (empty($nolog)) {
1415 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1419 if ($handle = opendir(
"$dir_osencoded")) {
1420 while (
false !== ($item = readdir($handle))) {
1422 $item = utf8_encode($item);
1425 if ($item !=
"." && $item !=
"..") {
1429 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1441 if (empty($onlysub)) {
1466 global $langs, $conf;
1469 $element = $object->element;
1471 if ($object->element ==
'order_supplier') {
1472 $dir = $conf->fournisseur->commande->dir_output;
1473 } elseif ($object->element ==
'invoice_supplier') {
1474 $dir = $conf->fournisseur->facture->dir_output;
1475 } elseif ($object->element ==
'project') {
1476 $dir = $conf->project->dir_output;
1477 } elseif ($object->element ==
'shipping') {
1478 $dir = $conf->expedition->dir_output.
'/sending';
1479 } elseif ($object->element ==
'delivery') {
1480 $dir = $conf->expedition->dir_output.
'/receipt';
1481 } elseif ($object->element ==
'fichinter') {
1482 $dir = $conf->ficheinter->dir_output;
1484 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1488 return 'ErrorObjectNoSupportedByFunction';
1492 $dir = $dir.
"/".$refsan;
1493 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1494 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1495 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1498 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1500 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1504 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1506 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1511 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1513 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1517 $multiple = $filepreviewold.
".";
1518 for ($i = 0; $i < 20; $i++) {
1519 $preview = $multiple.$i;
1521 if (file_exists($preview) && is_writable($preview)) {
1523 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1546 if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) {
1551 $element = $object->element;
1553 if ($object->element ==
'order_supplier') {
1554 $dir = $conf->fournisseur->dir_output.
'/commande';
1555 } elseif ($object->element ==
'invoice_supplier') {
1556 $dir = $conf->fournisseur->dir_output.
'/facture';
1557 } elseif ($object->element ==
'project') {
1558 $dir = $conf->project->dir_output;
1559 } elseif ($object->element ==
'shipping') {
1560 $dir = $conf->expedition->dir_output.
'/sending';
1561 } elseif ($object->element ==
'delivery') {
1562 $dir = $conf->expedition->dir_output.
'/receipt';
1563 } elseif ($object->element ==
'fichinter') {
1564 $dir = $conf->ficheinter->dir_output;
1566 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1570 $object->fetch_thirdparty();
1573 $dir = $dir.
"/".$objectref;
1574 $file = $dir.
"/".$objectref.
".meta";
1576 if (!is_dir($dir)) {
1581 if (is_countable($object->lines) && count($object->lines) > 0) {
1582 $nblines = count($object->lines);
1584 $client = $object->thirdparty->name.
" ".$object->thirdparty->address.
" ".$object->thirdparty->zip.
" ".$object->thirdparty->town;
1585 $meta =
"REFERENCE=\"".$object->ref.
"\"
1587 NB_ITEMS=\"" . $nblines.
"\"
1588 CLIENT=\"" . $client.
"\"
1589 AMOUNT_EXCL_TAX=\"" . $object->total_ht.
"\"
1590 AMOUNT=\"" . $object->total_ttc.
"\"\n";
1592 for ($i = 0; $i < $nblines; $i++) {
1594 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".$object->lines[$i]->qty.
"\"
1595 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".$object->lines[$i]->total_ht.
"\"
1596 ITEM_" . $i.
"_VAT=\"".$object->lines[$i]->tva_tx.
"\"
1597 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br($object->lines[$i]->desc)).
"\"
1602 $fp = fopen($file,
"w");
1610 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING);
1628 $listofpaths = array();
1629 $listofnames = array();
1630 $listofmimes = array();
1634 foreach ($listoffiles as $key => $val) {
1635 $listofpaths[] = $val[
'fullname'];
1636 $listofnames[] = $val[
'name'];
1640 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1641 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
1642 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
1643 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
1664 function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1, $object =
null)
1667 global $db, $user, $conf, $langs;
1671 if (!empty($_FILES[$varfiles])) {
1672 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' donotupdatesession='.$donotupdatesession.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1673 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1674 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1675 $langs->load(
"errors");
1676 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1682 $TFile = $_FILES[$varfiles];
1683 if (!is_array($TFile[
'name'])) {
1684 foreach ($TFile as $key => &$val) {
1689 $nbfile = count($TFile[
'name']);
1691 for ($i = 0; $i < $nbfile; $i++) {
1692 if (empty($TFile[
'name'][$i])) {
1697 $destfull = $upload_dir.
"/".$TFile[
'name'][$i];
1698 $destfile = $TFile[
'name'][$i];
1699 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1701 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1702 $destfull = $upload_dir.
"/".preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1703 $destfile = preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1706 $filenameto = basename($destfile);
1707 if (preg_match(
'/^\./', $filenameto)) {
1708 $langs->load(
"errors");
1709 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1714 $info = pathinfo($destfull);
1715 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1716 $info = pathinfo($destfile);
1717 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1725 global $dolibarr_main_restrict_os_commands;
1726 if (!empty($dolibarr_main_restrict_os_commands)) {
1727 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1728 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1729 if (in_array($destfile, $arrayofallowedcommand)) {
1730 $langs->load(
"errors");
1731 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
1737 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1739 if (is_numeric($resupload) && $resupload > 0) {
1740 global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
1742 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
1745 if ($generatethumbs) {
1751 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
1754 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
1759 if (empty($donotupdatesession)) {
1760 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1762 $formmail->trackid = $trackid;
1763 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
1767 if ($donotupdatesession == 1) {
1769 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false && !empty($conf->global->PRODUCT_ALLOW_EXTERNAL_DOWNLOAD)) $sharefile = 1;
1770 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile, $object);
1772 if ($allowoverwrite) {
1775 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
1782 $langs->load(
"errors");
1783 if ($resupload < 0) {
1785 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
1786 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"),
null,
'errors');
1798 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
1801 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
1802 $linkObject =
new Link($db);
1803 $linkObject->entity = $conf->entity;
1804 $linkObject->url = $link;
1805 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
1806 $linkObject->objectid =
GETPOST(
'objectid',
'int');
1807 $linkObject->label =
GETPOST(
'label',
'alpha');
1808 $res = $linkObject->create($user);
1809 $langs->load(
'link');
1816 $langs->load(
"errors");
1817 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
1837 global $db, $user, $conf, $langs, $_FILES;
1839 $keytodelete = $filenb;
1842 $listofpaths = array();
1843 $listofnames = array();
1844 $listofmimes = array();
1845 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1846 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
1847 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
1849 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
1850 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
1852 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
1853 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
1856 if ($keytodelete >= 0) {
1857 $pathtodelete = $listofpaths[$keytodelete];
1858 $filetodelete = $listofnames[$keytodelete];
1859 if (empty($donotdeletefile)) {
1865 if (empty($donotdeletefile)) {
1866 $langs->load(
"other");
1867 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
1869 if (empty($donotupdatesession)) {
1870 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1872 $formmail->trackid = $trackid;
1873 $formmail->remove_attached_files($keytodelete);
1895 global $db, $user, $conf;
1899 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1901 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
1902 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
1903 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1904 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1906 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1908 $ecmfile->filepath = $rel_dir;
1909 $ecmfile->filename = $filename;
1910 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
1911 $ecmfile->fullpath_orig = $fullpathorig;
1912 $ecmfile->gen_or_uploaded = $mode;
1913 $ecmfile->description =
'';
1914 $ecmfile->keywords =
'';
1916 if (is_object($object) && $object->id > 0) {
1917 $ecmfile->src_object_id = $object->id;
1918 if (isset($object->table_element)) {
1919 $ecmfile->src_object_type = $object->table_element;
1921 dol_syslog(
'Error: object ' . get_class($object) .
' has no table_element attribute.');
1924 if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description;
1925 if (isset($object->src_object_keywords)) $ecmfile->keywords = $object->src_object_keywords;
1928 if (!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE)) {
1933 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1937 $result = $ecmfile->create($user);
1956 global $conf, $db, $user;
1961 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
1967 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1969 $filename = basename($file);
1970 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1971 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1974 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
1975 $sql .=
' WHERE entity = '.$conf->entity;
1976 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
1978 $sql .=
" AND filename = '".$db->escape($file).
"'";
1981 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
1984 $resql = $db->query(
$sql);
1987 dol_syslog(__METHOD__.
' '.$db->lasterror(), LOG_ERR);
2015 if (class_exists(
'Imagick')) {
2016 $image =
new Imagick();
2018 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
2020 $ret = $image->readImage($filetoconvert);
2022 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2023 dol_syslog(
"Failed to read image using Imagick (Try to install package 'apt-get install php-imagick ghostscript' and check there is no policy to disable ".$ext.
" convertion in /etc/ImageMagick*/policy.xml): ".$e->getMessage(), LOG_WARNING);
2027 $ret = $image->setImageFormat($ext);
2029 if (empty($fileoutput)) {
2030 $fileoutput = $fileinput.
".".$ext;
2033 $count = $image->getNumberImages();
2035 if (!
dol_is_file($fileoutput) || is_writeable($fileoutput)) {
2037 $ret = $image->writeImages($fileoutput,
true);
2042 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2072 function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2079 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2082 if ($mode ==
'gz' && function_exists(
'gzencode')) {
2084 $compressdata = gzencode($data, 9);
2085 } elseif ($mode ==
'bz' && function_exists(
'bzcompress')) {
2087 $compressdata = bzcompress($data, 9);
2088 } elseif ($mode ==
'zstd' && function_exists(
'zstd_compress')) {
2090 $compressdata = zstd_compress($data, 9);
2091 } elseif ($mode ==
'zip') {
2092 if (class_exists(
'ZipArchive') && !empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS)) {
2095 $rootPath = realpath($inputfile);
2097 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2098 $zip =
new ZipArchive;
2100 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2101 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2105 $errormsg = $errorstring;
2112 $files =
new RecursiveIteratorIterator(
2113 new RecursiveDirectoryIterator($rootPath),
2114 RecursiveIteratorIterator::LEAVES_ONLY
2117 foreach ($files as $name => $file) {
2119 if (!$file->isDir()) {
2121 $filePath = $file->getPath();
2122 $fileName = $file->getFilename();
2123 $fileFullRealPath = $file->getRealPath();
2126 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2129 $zip->addFile($fileFullRealPath, $relativePath);
2136 dol_syslog(
"dol_compress_file success - ".count($zip->numFiles).
" files");
2140 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2143 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2144 $archive =
new PclZip($outputfile);
2145 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2147 if ($result === 0) {
2149 $errormsg = $archive->errorInfo(
true);
2151 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2152 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2153 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2157 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2158 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2161 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2167 if ($foundhandler) {
2168 $fp = fopen($outputfile,
"w");
2169 fwrite($fp, $compressdata);
2173 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2177 $errormsg = $errorstring;
2181 global $langs, $errormsg;
2182 $langs->load(
"errors");
2183 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2185 $errorstring =
"Failed to open file ".$outputfile;
2201 global $conf, $langs, $db;
2203 $fileinfo = pathinfo($inputfile);
2204 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2206 if ($fileinfo[
"extension"] ==
"zip") {
2207 if (defined(
'ODTPHP_PATHTOPCLZIP') && empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS)) {
2208 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2209 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2210 $archive =
new PclZip($inputfile);
2216 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2218 if (!is_array($result) && $result <= 0) {
2219 return array(
'error'=>$archive->errorInfo(
true));
2224 foreach ($result as $key => $val) {
2225 if ($val[
'status'] ==
'path_creation_fail') {
2226 $langs->load(
"errors");
2228 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2236 return array(
'error'=>$errmsg);
2241 if (class_exists(
'ZipArchive')) {
2242 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2243 $zip =
new ZipArchive;
2244 $res = $zip->open($inputfile);
2245 if ($res ===
true) {
2251 for ($i = 0; $i < $zip->numFiles; $i++) {
2252 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2253 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2256 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2262 return array(
'error'=>
'ErrUnzipFails');
2266 return array(
'error'=>
'ErrNoZipEngine');
2267 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2268 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2269 $utils =
new Utils($db);
2276 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2277 if ($extension ==
"tar") {
2280 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2281 if ($resarray[
"result"] != 0) {
2282 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2286 if ($fileinfo[
"extension"] ==
"gz") {
2288 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2290 } elseif ($fileinfo[
"extension"] ==
"zst") {
2293 return array(
'error'=>
'ErrorBadFileExtension');
2296 $cmd .=
' > '.$outputfilename;
2298 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2299 if ($resarray[
"result"] != 0) {
2300 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2301 if ($errfilecontent) {
2302 $resarray[
"error"] .=
" - ".$errfilecontent;
2306 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2309 return array(
'error'=>
'ErrorBadFileExtension');
2325 function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask = 0)
2331 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2333 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2334 global $langs, $errormsg;
2335 $langs->load(
"errors");
2336 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2341 if ($mode ==
'gz') {
2343 } elseif ($mode ==
'bz') {
2345 } elseif ($mode ==
'zip') {
2359 if (class_exists(
'ZipArchive')) {
2363 $zip =
new ZipArchive();
2364 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2366 global $langs, $errormsg;
2367 $langs->load(
"errors");
2368 $errormsg = $langs->trans(
"ErrorFailedToWriteInFile", $outputfile);
2375 $files =
new RecursiveIteratorIterator(
2376 new RecursiveDirectoryIterator($inputdir),
2377 RecursiveIteratorIterator::LEAVES_ONLY
2381 foreach ($files as $name => $file) {
2383 if (!$file->isDir()) {
2385 $filePath = $file->getPath();
2386 $fileName = $file->getFilename();
2387 $fileFullRealPath = $file->getRealPath();
2390 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2393 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2395 $zip->addFile($fileFullRealPath, $relativePath);
2403 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
2404 $newmask = $conf->global->MAIN_UMASK;
2406 if (empty($newmask)) {
2407 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2417 if (!$foundhandler) {
2418 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2424 global $langs, $errormsg;
2425 $langs->load(
"errors");
2426 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2428 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2445 function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook =
false, $mode =
'')
2447 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2448 return isset($tmparray[0])?$tmparray[0]:
null;
2466 global $conf, $db, $user, $hookmanager;
2467 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2470 if (!is_object($fuser)) {
2474 if (empty($modulepart)) {
2475 return 'ErrorBadParameter';
2477 if (empty($entity)) {
2485 if ($modulepart ==
'users') {
2486 $modulepart =
'user';
2488 if ($modulepart ==
'tva') {
2489 $modulepart =
'tax-vat';
2493 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2497 $sqlprotectagainstexternals =
'';
2501 if (empty($refname)) {
2502 $refname = basename(dirname($original_file).
"/");
2503 if ($refname ==
'thumbs') {
2505 $refname = basename(dirname(dirname($original_file)).
"/");
2512 $download =
'download';
2513 if ($mode ==
'write') {
2516 $download =
'upload';
2520 if ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2521 if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2522 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2525 $original_file = $conf->medias->multidir_output[$entity].
'/'.$original_file;
2526 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2528 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.log$/', basename($original_file)));
2529 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2530 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2532 $accessallowed = $user->admin;
2533 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2534 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2536 $accessallowed = ($fuser->rights->website->write && preg_match(
'/\.jpg$/i', basename($original_file)));
2537 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2538 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2541 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2544 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2545 $original_file = $dirins.
'/'.$original_file;
2546 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
2549 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
2550 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
2553 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2556 $original_file = $conf->user->dir_output.
'/'.$original_file;
2557 } elseif ($modulepart ==
'userphotopublic' && !empty($conf->user->dir_output)) {
2561 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2563 $tmpobject =
new User($db);
2564 $tmpobject->fetch($reg[0],
'',
'', 1);
2566 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2568 global $dolibarr_main_instance_unique_id;
2569 $encodedsecurekey =
dol_hash($dolibarr_main_instance_unique_id.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2570 if ($encodedsecurekey == $securekey) {
2579 $original_file = $conf->user->dir_output.
'/'.$original_file;
2580 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
2583 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
2584 } elseif ($modulepart ==
'memberphoto' && !empty($conf->adherent->dir_output)) {
2587 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2590 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
2591 } elseif ($modulepart ==
'apercufacture' && !empty($conf->facture->multidir_output[$entity])) {
2593 if ($fuser->hasRight(
'facture', $lire)) {
2596 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2597 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
2599 if ($fuser->hasRight(
'propal', $lire)) {
2602 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2603 } elseif ($modulepart ==
'apercucommande' && !empty($conf->commande->multidir_output[$entity])) {
2605 if ($fuser->hasRight(
'commande', $lire)) {
2608 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2609 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
2611 if ($fuser->hasRight(
'ficheinter', $lire)) {
2614 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2615 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contrat->multidir_output[$entity])) {
2617 if ($fuser->hasRight(
'contrat', $lire)) {
2620 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2621 } elseif (($modulepart ==
'apercusupplier_proposal' || $modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
2623 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
2626 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
2627 } elseif (($modulepart ==
'apercusupplier_order' || $modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
2629 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2632 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2633 } elseif (($modulepart ==
'apercusupplier_invoice' || $modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
2635 if ($fuser->hasRight(
'fournisseur', $lire)) {
2638 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2639 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
2640 if ($fuser->hasRight(
'holiday', $read) || !empty($fuser->rights->holiday->readall) || preg_match(
'/^specimen/i', $original_file)) {
2643 if ($refname && empty($fuser->rights->holiday->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2644 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
2645 $tmpholiday =
new Holiday($db);
2646 $tmpholiday->fetch(
'', $refname);
2647 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
2650 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
2651 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
2652 if ($fuser->hasRight(
'expensereport', $lire) || !empty($fuser->rights->expensereport->readall) || preg_match(
'/^specimen/i', $original_file)) {
2655 if ($refname && empty($fuser->rights->expensereport->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2656 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
2658 $tmpexpensereport->fetch(
'', $refname);
2659 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
2662 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2663 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
2665 if ($fuser->hasRight(
'expensereport', $lire)) {
2668 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2669 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
2671 if ($fuser->hasRight(
'propal', $lire)) {
2674 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
2675 } elseif ($modulepart ==
'orderstats' && !empty($conf->commande->dir_temp)) {
2677 if ($fuser->hasRight(
'commande', $lire)) {
2680 $original_file = $conf->commande->dir_temp.
'/'.$original_file;
2681 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2682 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2685 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
2686 } elseif ($modulepart ==
'billstats' && !empty($conf->facture->dir_temp)) {
2688 if ($fuser->hasRight(
'facture', $lire)) {
2691 $original_file = $conf->facture->dir_temp.
'/'.$original_file;
2692 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2693 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
2696 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
2697 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
2699 if ($fuser->hasRight(
'expedition', $lire)) {
2702 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
2703 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
2705 if ($fuser->hasRight(
'deplacement', $lire)) {
2708 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
2709 } elseif ($modulepart ==
'memberstats' && !empty($conf->adherent->dir_temp)) {
2711 if ($fuser->hasRight(
'adherent', $lire)) {
2714 $original_file = $conf->adherent->dir_temp.
'/'.$original_file;
2715 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
2717 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
2720 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
2721 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
2723 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
2726 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
2727 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
2728 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2730 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
2733 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2734 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2736 $tmpobject->fetch((
int) $refname);
2737 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
2738 if ($user->socid && $tmpobject->socid) {
2743 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2744 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
2746 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
2747 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2749 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
2752 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
2753 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
2755 if ($fuser->rights->prelevement->bons->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2758 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
2759 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
2762 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
2763 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
2766 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
2767 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
2770 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
2771 } elseif ($modulepart ==
'barcode') {
2776 $original_file =
'';
2777 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
2780 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
2781 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
2784 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
2785 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
2788 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
2789 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
2791 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2792 if ($fuser->id == (
int) $refname) {
2795 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
2798 $original_file = $conf->user->dir_output.
'/'.$original_file;
2799 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
2801 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2802 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2804 if ($fuser->rights->societe->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2807 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
2808 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
2809 } elseif ($modulepart ==
'contact' && !empty($conf->societe->multidir_output[$entity])) {
2811 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2812 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2814 if ($fuser->hasRight(
'societe', $lire)) {
2817 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
2818 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->facture->multidir_output[$entity])) {
2820 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2823 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2824 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
2825 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
2827 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2830 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2831 } elseif ($modulepart ==
'massfilesarea_orders') {
2832 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2835 $original_file = $conf->commande->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2836 } elseif ($modulepart ==
'massfilesarea_sendings') {
2837 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2840 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
2841 } elseif ($modulepart ==
'massfilesarea_invoices') {
2842 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2845 $original_file = $conf->facture->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2846 } elseif ($modulepart ==
'massfilesarea_expensereport') {
2847 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2850 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2851 } elseif ($modulepart ==
'massfilesarea_interventions') {
2852 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2855 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2856 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
2857 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2860 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2861 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
2862 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2865 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2866 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
2867 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2870 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2871 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contrat->dir_output)) {
2872 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2875 $original_file = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2876 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
2878 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2881 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2882 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2883 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
2885 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2888 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
2890 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
2892 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2895 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2896 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
2897 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->commande->multidir_output[$entity])) {
2899 if ($fuser->rights->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2902 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2903 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
2904 } elseif ($modulepart ==
'project' && !empty($conf->project->dir_output)) {
2906 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2909 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2910 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
2911 $tmpproject =
new Project($db);
2912 $tmpproject->fetch(
'', $refname);
2913 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
2916 $original_file = $conf->project->dir_output.
'/'.$original_file;
2917 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2918 } elseif ($modulepart ==
'project_task' && !empty($conf->project->dir_output)) {
2919 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2922 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2923 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
2924 $tmptask =
new Task($db);
2925 $tmptask->fetch(
'', $refname);
2926 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
2929 $original_file = $conf->project->dir_output.
'/'.$original_file;
2930 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2931 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
2933 if ($fuser->rights->fournisseur->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2936 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2937 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2938 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
2940 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2943 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2944 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2945 } elseif ($modulepart ==
'supplier_payment') {
2947 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2950 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
2951 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2952 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->facture->dir_output)) {
2954 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2957 if ($fuser->socid > 0) {
2958 $original_file = $conf->facture->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
2960 $original_file = $conf->facture->dir_output.
'/payments/'.$original_file;
2962 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
2964 if ($fuser->rights->accounting->bind->write || preg_match(
'/^specimen/i', $original_file)) {
2967 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
2968 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty($conf->expedition->dir_output)) {
2970 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2973 $original_file = $conf->expedition->dir_output.
"/".(strpos(
'sending/', $original_file) === 0 ?
'' :
'sending/').$original_file;
2975 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
2977 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2980 $original_file = $conf->expedition->dir_output.
"/".(strpos(
'receipt/', $original_file) === 0 ?
'' :
'receipt/').$original_file;
2981 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2983 if ($fuser->hasRight(
'agenda',
'myactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
2986 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2987 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
2989 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
2992 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
2993 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
2995 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
2996 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2998 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3002 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
3004 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
3006 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3008 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
3009 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3011 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3015 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3017 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3019 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3020 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3022 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3026 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3028 } elseif ($modulepart ==
'contract' && !empty($conf->contrat->multidir_output[$entity])) {
3030 if ($fuser->rights->contrat->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3033 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
3034 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3035 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
3037 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3040 $original_file = $conf->don->dir_output.
'/'.$original_file;
3041 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3043 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3046 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3047 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3049 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3053 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3054 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3056 if ($fuser->hasRight(
'banque', $lire)) {
3059 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3060 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3063 $accessallowed = $user->rights->export->lire;
3064 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3065 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3067 $accessallowed = $user->rights->import->run;
3068 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3069 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3071 $accessallowed = $user->rights->recruitment->recruitmentjobposition->read;
3072 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3073 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3076 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3077 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3079 if ($fuser->admin) {
3082 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3083 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3085 if ($fuser->admin) {
3088 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3089 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3093 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3096 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3097 } elseif ($modulepart ==
'member' && !empty($conf->adherent->dir_output)) {
3099 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3102 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
3103 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3106 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3116 if (preg_match(
'/^specimen/i', $original_file)) {
3119 if ($fuser->admin) {
3123 $tmpmodulepart = explode(
'-', $modulepart);
3124 if (!empty($tmpmodulepart[1])) {
3125 $modulepart = $tmpmodulepart[0];
3126 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3131 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3132 if (empty($conf->{$reg[1]}->dir_temp)) {
3133 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3136 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3139 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3140 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3141 if (empty($conf->{$reg[1]}->dir_temp)) {
3142 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3145 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3148 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$original_file;
3149 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3150 if (empty($conf->{$reg[1]}->dir_output)) {
3151 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3154 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3157 $original_file = $conf->{$reg[1]}->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3158 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3159 if (empty($conf->{$reg[1]}->dir_output)) {
3160 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3163 if ($fuser->rights->{$reg[1]}->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3166 $original_file = $conf->{$reg[1]}->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3168 if (empty($conf->$modulepart->dir_output)) {
3169 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
'). The module for this modulepart value may not be activated.');
3174 $partsofdirinoriginalfile = explode(
'/', $original_file);
3175 if (!empty($partsofdirinoriginalfile[1])) {
3176 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3177 if ($partofdirinoriginalfile && !empty($fuser->rights->$modulepart->$partofdirinoriginalfile) && ($fuser->rights->$modulepart->$partofdirinoriginalfile->{$lire} || $fuser->rights->$modulepart->$partofdirinoriginalfile->{$read})) {
3181 if (!empty($fuser->rights->$modulepart->{$lire}) || !empty($fuser->rights->$modulepart->{$read})) {
3185 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3186 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3188 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3192 $parameters = array(
3193 'modulepart' => $modulepart,
3194 'original_file' => $original_file,
3195 'entity' => $entity,
3200 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters, $object);
3202 if (!empty($hookmanager->resArray[
'original_file'])) {
3203 $original_file = $hookmanager->resArray[
'original_file'];
3205 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3206 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3208 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3209 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3215 'accessallowed' => ($accessallowed ? 1 : 0),
3216 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3217 'original_file' => $original_file
3236 $cachefile = $directory.$filename;
3237 file_put_contents($cachefile, serialize($object), LOCK_EX);
3252 $cachefile = $directory.$filename;
3253 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3266 $cachefile = $directory.$filename;
3267 $object = unserialize(file_get_contents($cachefile));
3283 function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3287 $exclude =
'install';
3289 foreach ($dir->md5file as $file) {
3290 $filename = $path.$file[
'name'];
3291 $file_list[
'insignature'][] = $filename;
3292 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3293 $expectedmd5 = (string) $file;
3297 if (!file_exists($pathref.
'/'.$filename)) {
3298 $file_list[
'missing'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize);
3300 $md5_local = md5_file($pathref.
'/'.$filename);
3302 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3303 $checksumconcat[] = $expectedmd5;
3305 if ($md5_local != $expectedmd5) {
3306 $file_list[
'updated'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize,
'md5'=>(
string) $md5_local);
3308 $checksumconcat[] = $md5_local;
3313 foreach ($dir->dir as $subdir) {
3314 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);