40@phan-var-force string $upload_dir
41@phan-var-force string $upload_dirold
42@phan-var-force string $confirm
43@phan-var-force string $forceFullTextIndexation
47if (
GETPOSTINT(
'uploadform') && empty($_POST) && empty($_FILES)) {
48 dol_syslog(
"The PHP parameter 'post_max_size' is too low. All POST parameters and FILES were set to empty.");
49 $langs->loadLangs(array(
"errors",
"install"));
50 print $langs->trans(
"ErrorFileSizeTooLarge").
' ';
51 print $langs->trans(
"ErrorGoBackAndCorrectParameters");
56 ||
GETPOST(
'linkit',
'restricthtml')
57 || ($action ==
'confirm_deletefile' && $confirm ==
'yes')
58 || ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha'))
59 || ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha'))) && empty($permissiontoadd)) {
60 dol_syslog(
'The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before or is set to false.');
61 print
'The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before or is set to false.';
69 if (!empty($_FILES) && is_array($_FILES[
'userfile'])) {
70 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
72 if (is_array($_FILES[
'userfile'][
'tmp_name'])) {
73 $userfiles = $_FILES[
'userfile'][
'tmp_name'];
74 $filearrayis =
'array';
76 $userfiles = array(0 => $_FILES[
'userfile'][
'tmp_name']);
77 $filearrayis =
'string';
80 foreach ($userfiles as $key => $userfile) {
81 if ($filearrayis ==
'array') {
82 $fileerror = $_FILES[
'userfile'][
'error'][$key];
83 $fileoriginname = $_FILES[
'userfile'][
'name'][$key];
85 $fileerror = $_FILES[
'userfile'][
'error'];
86 $fileoriginname = $_FILES[
'userfile'][
'name'];
89 if (empty($userfile)) {
91 if ($fileerror == 1 || $fileerror == 2) {
94 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
97 if (preg_match(
'/__.*__/', $fileoriginname)) {
106 if (
GETPOST(
'section_dir',
'alpha')) {
109 $allowoverwrite = (
GETPOSTINT(
'overwritefile') ? 1 : 0);
110 $forceFullTextIndexation = (!empty($forceFullTextIndexation) ? $forceFullTextIndexation :
'');
112 if (!empty($upload_dirold) &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
113 $result =
dol_add_file_process($upload_dirold, $allowoverwrite, 1,
'userfile',
GETPOST(
'savingdocmask',
'alpha'),
null,
'', $generatethumbs,
$object, empty($forceFullTextIndexation) ? 0 : $forceFullTextIndexation);
114 } elseif (!empty($upload_dir)) {
115 $result =
dol_add_file_process($upload_dir, $allowoverwrite, 1,
'userfile',
GETPOST(
'savingdocmask',
'alpha'),
null,
'', $generatethumbs,
$object, empty($forceFullTextIndexation) ? 0 : $forceFullTextIndexation);
120 $link =
GETPOST(
'link',
'alpha');
122 if (substr($link, 0, 7) !=
'http://'
123 && substr($link, 0, 8) !=
'https://'
124 && substr($link, 0, 7) !=
'davs://'
125 && (substr($link, 0, 7) !=
'file://' || !
getDolGlobalString(
'MAIN_ALLOW_LINK_STARTING_WITH_FILE'))) {
126 $link =
'http://'.$link;
130 $newUrlArray = parse_url($link);
134 if (!empty($newUrlArray[
'path']) && preg_match(
'/\.svg$/i', $newUrlArray[
'path'])) {
136 $langs->load(
"errors");
137 setEventMessages($langs->trans(
'ErrorSVGFilesNotAllowedAsLinksWithout',
'MAIN_ALLOW_SVG_FILES_AS_EXTERNAL_LINKS'),
null,
'errors');
153if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && !empty($permissiontoadd)) {
154 $urlfile =
GETPOST(
'urlfile',
'alpha', 0,
null,
null, 1);
155 if (
GETPOST(
'section',
'alpha')) {
157 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
159 $urlfile = basename($urlfile);
160 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
161 if (!empty($upload_dirold)) {
162 $fileold = $upload_dirold.
"/".$urlfile;
168 $dir = dirname($file).
'/';
169 $dirthumb = $dir.
'/thumbs/';
172 if (!empty($fileold)) {
179 if (preg_match(
'/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff|\.webp|\.xpm|\.xbm|\.avif)$/i', $file, $regs)) {
180 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_small'.$regs[0]);
181 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
185 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_mini'.$regs[0]);
186 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
192 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $urlfile),
null,
'errors');
195 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
197 $link->fetch($linkid);
199 if (!is_object(
$object) || $link->objecttype !=
$object->element || $link->objectid !=
$object->id) {
202 $res = $link->delete($user);
204 $langs->load(
'link');
206 setEventMessages($langs->trans(
"LinkRemoved", $link->label),
null,
'mesgs');
208 if (count($link->errors)) {
211 setEventMessages($langs->trans(
"ErrorFailedToDeleteLink", $link->label),
null,
'errors');
217 if (!empty($backtopage)) {
218 header(
'Location: '.$backtopage);
221 $tmpurl = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(GETPOST(
'section_dir',
'alpha') ?
'§ion_dir='.urlencode(
GETPOST(
'section_dir',
'alpha')) :
'').(!empty($withproject) ?
'&withproject=1' :
'');
222 header(
'Location: '.$tmpurl);
226} elseif ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha') && !empty($permissiontoadd)) {
227 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
233 if (!is_object(
$object) || $link->objecttype !=
$object->element || $link->objectid !=
$object->id) {
236 $link->url =
GETPOST(
'link',
'alpha');
237 if (substr($link->url, 0, 7) !=
'http://'
238 && substr($link->url, 0, 8) !=
'https://'
239 && substr($link->url, 0, 7) !=
'davs://'
240 && (substr($link->url, 0, 7) !=
'file://' || !
getDolGlobalString(
'MAIN_ALLOW_LINK_STARTING_WITH_FILE'))) {
241 $link->url =
'http://'.$link->url;
243 $link->label =
GETPOST(
'label',
'alphanohtml');
245 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
247 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
252 $res = $link->update($user);
254 setEventMessages($langs->trans(
"ErrorFailedToUpdateLink", $link->label),
null,
'mesgs');
259} elseif ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha') && !empty($permissiontoadd)) {
261 if (!empty($upload_dir)) {
268 if (preg_match(
'/__.*__/', $filenameto)) {
275 global $dolibarr_main_restrict_os_commands;
276 if (!empty($dolibarr_main_restrict_os_commands)) {
277 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
278 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
279 if (in_array(basename($filenameto), $arrayofallowedcommand)) {
281 $langs->load(
"errors");
282 setEventMessages($langs->trans(
"ErrorFilenameReserved", basename($filenameto)),
null,
'errors');
287 if (empty($error) && $filenamefrom != $filenameto) {
290 $dirforfile = $upload_dir;
291 if (!empty($upload_dirold) && !
dol_is_file($upload_dir.
'/'.$filenamefrom) &&
dol_is_file($upload_dirold.
'/'.$filenamefrom)) {
292 $dirforfile = $upload_dirold;
300 $publicmediasdirwithslash =
$conf->medias->multidir_output[
$conf->entity];
301 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
302 $publicmediasdirwithslash .=
'/';
305 if (strpos($dirforfile, $publicmediasdirwithslash) !== 0) {
306 $filenameto .=
'.noexe';
310 if ($filenamefrom && $filenameto) {
311 $srcpath = $dirforfile.
'/'.$filenamefrom;
312 $destpath = $dirforfile.
'/'.$filenameto;
322 $reshook = $hookmanager->initHooks(array(
'actionlinkedfiles'));
323 $parameters = array(
'filenamefrom' => $filenamefrom,
'filenameto' => $filenameto,
'upload_dir' => $dirforfile);
324 $reshook = $hookmanager->executeHooks(
'renameUploadedFile', $parameters,
$object);
326 if (empty($reshook)) {
327 if (preg_match(
'/^\./', $filenameto)) {
328 $langs->load(
"errors");
329 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
330 } elseif (!file_exists($destpath)) {
338 if (
GETPOST(
'modulepart',
'aZ09') ==
'medias') {
342 if ($generatethumbs) {
354 $langs->load(
"errors");
355 setEventMessages($langs->trans(
"ErrorFailToRenameFile", $filenamefrom, $filenameto),
null,
'errors');
358 $langs->load(
"errors");
359 setEventMessages($langs->trans(
"ErrorDestinationAlreadyExists", $filenameto),
null,
'errors');
368 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
370 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
372 $result = $ecmfile->fetch(
GETPOSTINT(
'ecmfileid'));
375 if (empty($ecmfile->share)) {
376 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
380 $ecmfile->share =
'';
382 $result = $ecmfile->update($user);
if(! $sortfield) if(! $sortorder) $object
Class to manage ECM files.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $keyforsourcefile='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='', $mode=0)
Get and save an upload file (for example after submitting a new file in a mail form).
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.