32if (
GETPOSTINT(
'uploadform') && empty($_POST) && empty($_FILES)) {
33 dol_syslog(
"The PHP parameter 'post_max_size' is too low. All POST parameters and FILES were set to empty.");
34 $langs->loadLangs(array(
"errors",
"install"));
35 print $langs->trans(
"ErrorFileSizeTooLarge").
' ';
36 print $langs->trans(
"ErrorGoBackAndCorrectParameters");
41 ||
GETPOST(
'linkit',
'restricthtml')
42 || ($action ==
'confirm_deletefile' && $confirm ==
'yes')
43 || ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha'))
44 || ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha'))) && empty($permissiontoadd)) {
45 dol_syslog(
'The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before.');
46 print
'The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before.';
53 if (!empty($_FILES) && is_array($_FILES[
'userfile'])) {
54 if (is_array($_FILES[
'userfile'][
'tmp_name'])) {
55 $userfiles = $_FILES[
'userfile'][
'tmp_name'];
57 $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
60 foreach ($userfiles as $key => $userfile) {
61 if (empty($_FILES[
'userfile'][
'tmp_name'][$key])) {
63 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
66 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
69 if (preg_match(
'/__.*__/', $_FILES[
'userfile'][
'name'][$key])) {
78 if (
GETPOST(
'section_dir',
'alpha')) {
81 $allowoverwrite = (
GETPOSTINT(
'overwritefile') ? 1 : 0);
83 if (!empty($upload_dirold) &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
85 } elseif (!empty($upload_dir)) {
91 $link =
GETPOST(
'link',
'alpha');
93 if (substr($link, 0, 7) !=
'http://' && substr($link, 0, 8) !=
'https://' && substr($link, 0, 7) !=
'file://' && substr($link, 0, 7) !=
'davs://') {
94 $link =
'http://'.$link;
98 $newUrlArray = parse_url($link);
102 if (!empty($newUrlArray[
'path']) && preg_match(
'/\.svg$/i', $newUrlArray[
'path'])) {
104 $langs->load(
"errors");
105 setEventMessages($langs->trans(
'ErrorSVGFilesNotAllowedAsLinksWithout',
'MAIN_ALLOW_SVG_FILES_AS_EXTERNAL_LINKS'),
null,
'errors');
122if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && !empty($permissiontoadd)) {
123 $urlfile =
GETPOST(
'urlfile',
'alpha', 0,
null,
null, 1);
124 if (
GETPOST(
'section',
'alpha')) {
126 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
128 $urlfile = basename($urlfile);
129 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
130 if (!empty($upload_dirold)) {
131 $fileold = $upload_dirold.
"/".$urlfile;
138 $dir = dirname($file).
'/';
139 $dirthumb = $dir.
'/thumbs/';
142 if (!empty($fileold)) {
149 if (preg_match(
'/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i', $file, $regs)) {
150 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_small'.$regs[0]);
151 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
155 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_mini'.$regs[0]);
156 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
162 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $urlfile),
null,
'errors');
165 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
166 $link =
new Link($db);
167 $link->fetch($linkid);
168 $res = $link->delete($user);
170 $langs->load(
'link');
172 setEventMessages($langs->trans(
"LinkRemoved", $link->label),
null,
'mesgs');
174 if (count($link->errors)) {
177 setEventMessages($langs->trans(
"ErrorFailedToDeleteLink", $link->label),
null,
'errors');
183 if (!empty($backtopage)) {
184 header(
'Location: '.$backtopage);
187 $tmpurl = $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(GETPOST(
'section_dir',
'alpha') ?
'§ion_dir='.urlencode(
GETPOST(
'section_dir',
'alpha')) :
'').(!empty($withproject) ?
'&withproject=1' :
'');
188 header(
'Location: '.$tmpurl);
192} elseif ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha') && !empty($permissiontoadd)) {
193 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
195 $link =
new Link($db);
198 $link->url =
GETPOST(
'link',
'alpha');
199 if (substr($link->url, 0, 7) !=
'http://' && substr($link->url, 0, 8) !=
'https://' && substr($link->url, 0, 7) !=
'file://') {
200 $link->url =
'http://'.$link->url;
202 $link->label =
GETPOST(
'label',
'alphanohtml');
203 $res = $link->update($user);
205 setEventMessages($langs->trans(
"ErrorFailedToUpdateLink", $link->label),
null,
'mesgs');
210} elseif ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha') && !empty($permissiontoadd)) {
212 if (!empty($upload_dir)) {
219 if (preg_match(
'/__.*__/', $filenameto)) {
226 global $dolibarr_main_restrict_os_commands;
227 if (!empty($dolibarr_main_restrict_os_commands)) {
228 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
229 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
230 if (in_array(basename($filenameto), $arrayofallowedcommand)) {
232 $langs->load(
"errors");
233 setEventMessages($langs->trans(
"ErrorFilenameReserved", basename($filenameto)),
null,
'errors');
238 if (empty($error) && $filenamefrom != $filenameto) {
244 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
245 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
246 $publicmediasdirwithslash .=
'/';
249 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
250 $filenameto .=
'.noexe';
254 if ($filenamefrom && $filenameto) {
255 $srcpath = $upload_dir.
'/'.$filenamefrom;
256 $destpath = $upload_dir.
'/'.$filenameto;
257 if ($modulepart ==
"ticket" && !
dol_is_file($srcpath)) {
258 $srcbis = $conf->agenda->dir_output.
'/'.
GETPOST(
'section_dir').$filenamefrom;
261 $destpath = $conf->agenda->dir_output.
'/'.
GETPOST(
'section_dir').$filenameto;
265 $reshook = $hookmanager->initHooks(array(
'actionlinkedfiles'));
266 $parameters = array(
'filenamefrom' => $filenamefrom,
'filenameto' => $filenameto,
'upload_dir' => $upload_dir);
267 $reshook = $hookmanager->executeHooks(
'renameUploadedFile', $parameters,
$object);
269 if (empty($reshook)) {
270 if (preg_match(
'/^\./', $filenameto)) {
271 $langs->load(
"errors");
272 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
273 } elseif (!file_exists($destpath)) {
274 $result =
dol_move($srcpath, $destpath);
281 if (
GETPOST(
'modulepart',
'aZ09') ==
'medias') {
285 if ($generatethumbs) {
297 $langs->load(
"errors");
298 setEventMessages($langs->trans(
"ErrorFailToRenameFile", $filenamefrom, $filenameto),
null,
'errors');
301 $langs->load(
"errors");
302 setEventMessages($langs->trans(
"ErrorDestinationAlreadyExists", $filenameto),
null,
'errors');
311 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
313 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
315 $result = $ecmfile->fetch(
GETPOSTINT(
'ecmfileid'));
318 if (empty($ecmfile->share)) {
319 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
323 $ecmfile->share =
'';
325 $result = $ecmfile->update($user);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage ECM files.
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_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.