31if (
GETPOST(
'uploadform',
'int') && empty($_POST) && empty($_FILES)) {
32 dol_syslog(
"The PHP parameter 'post_max_size' is too low. All POST parameters and FILES were set to empty.");
33 $langs->loadLangs(array(
"errors",
"install"));
34 print $langs->trans(
"ErrorFileSizeTooLarge").
' ';
35 print $langs->trans(
"ErrorGoBackAndCorrectParameters");
40 ||
GETPOST(
'linkit',
'restricthtml')
41 || ($action ==
'confirm_deletefile' && $confirm ==
'yes')
42 || ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha'))
43 || ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha'))) && empty($permissiontoadd)) {
44 dol_syslog(
'The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before.');
45 print
'The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before.';
52 if (!empty($_FILES) && is_array($_FILES[
'userfile'])) {
53 if (is_array($_FILES[
'userfile'][
'tmp_name'])) {
54 $userfiles = $_FILES[
'userfile'][
'tmp_name'];
56 $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
59 foreach ($userfiles as $key => $userfile) {
60 if (empty($_FILES[
'userfile'][
'tmp_name'][$key])) {
62 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
65 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
68 if (preg_match(
'/__.*__/', $_FILES[
'userfile'][
'name'][$key])) {
77 if (
GETPOST(
'section_dir',
'alpha')) {
80 $allowoverwrite = (
GETPOST(
'overwritefile',
'int') ? 1 : 0);
82 if (!empty($upload_dirold) &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
83 $result =
dol_add_file_process($upload_dirold, $allowoverwrite, 1,
'userfile',
GETPOST(
'savingdocmask',
'alpha'),
null,
'', $generatethumbs, $object);
84 } elseif (!empty($upload_dir)) {
85 $result =
dol_add_file_process($upload_dir, $allowoverwrite, 1,
'userfile',
GETPOST(
'savingdocmask',
'alpha'),
null,
'', $generatethumbs, $object);
90 $link =
GETPOST(
'link',
'alpha');
92 if (substr($link, 0, 7) !=
'http://' && substr($link, 0, 8) !=
'https://' && substr($link, 0, 7) !=
'file://' && substr($link, 0, 7) !=
'davs://') {
93 $link =
'http://'.$link;
97 $newUrlArray = parse_url($link);
101 if (!empty($newUrlArray[
'path']) && preg_match(
'/\.svg$/i', $newUrlArray[
'path'])) {
103 $langs->load(
"errors");
104 setEventMessages($langs->trans(
'ErrorSVGFilesNotAllowedAsLinksWithout',
'MAIN_ALLOW_SVG_FILES_AS_EXTERNAL_LINKS'),
null,
'errors');
121if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && !empty($permissiontoadd)) {
122 $urlfile =
GETPOST(
'urlfile',
'alpha', 0,
null,
null, 1);
123 if (
GETPOST(
'section',
'alpha')) {
125 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
127 $urlfile = basename($urlfile);
128 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
129 if (!empty($upload_dirold)) {
130 $fileold = $upload_dirold.
"/".$urlfile;
133 $linkid =
GETPOST(
'linkid',
'int');
137 $dir = dirname($file).
'/';
138 $dirthumb = $dir.
'/thumbs/';
140 $ret =
dol_delete_file($file, 0, 0, 0, (is_object($object) ? $object : null));
141 if (!empty($fileold)) {
142 dol_delete_file($fileold, 0, 0, 0, (is_object($object) ? $object : null));
148 if (preg_match(
'/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i', $file, $regs)) {
149 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_small'.$regs[0]);
150 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
154 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_mini'.$regs[0]);
155 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
161 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $urlfile),
null,
'errors');
164 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
165 $link =
new Link($db);
166 $link->fetch($linkid);
167 $res = $link->delete($user);
169 $langs->load(
'link');
171 setEventMessages($langs->trans(
"LinkRemoved", $link->label),
null,
'mesgs');
173 if (count($link->errors)) {
176 setEventMessages($langs->trans(
"ErrorFailedToDeleteLink", $link->label),
null,
'errors');
181 if (is_object($object) && $object->id > 0) {
182 if (!empty($backtopage)) {
183 header(
'Location: '.$backtopage);
186 $tmpurl = $_SERVER[
"PHP_SELF"].
'?id='.$object->id.(GETPOST(
'section_dir',
'alpha') ?
'§ion_dir='.urlencode(
GETPOST(
'section_dir',
'alpha')) :
'').(!empty($withproject) ?
'&withproject=1' :
'');
187 header(
'Location: '.$tmpurl);
191} elseif ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha') && !empty($permissiontoadd)) {
192 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
194 $link =
new Link($db);
195 $f = $link->fetch(
GETPOST(
'linkid',
'int'));
197 $link->url =
GETPOST(
'link',
'alpha');
198 if (substr($link->url, 0, 7) !=
'http://' && substr($link->url, 0, 8) !=
'https://' && substr($link->url, 0, 7) !=
'file://') {
199 $link->url =
'http://'.$link->url;
201 $link->label =
GETPOST(
'label',
'alphanohtml');
202 $res = $link->update($user);
204 setEventMessages($langs->trans(
"ErrorFailedToUpdateLink", $link->label),
null,
'mesgs');
209} elseif ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha') && !empty($permissiontoadd)) {
211 if (!empty($upload_dir)) {
218 if (preg_match(
'/__.*__/', $filenameto)) {
225 global $dolibarr_main_restrict_os_commands;
226 if (!empty($dolibarr_main_restrict_os_commands)) {
227 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
228 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
229 if (in_array(basename($filenameto), $arrayofallowedcommand)) {
231 $langs->load(
"errors");
232 setEventMessages($langs->trans(
"ErrorFilenameReserved", basename($filenameto)),
null,
'errors');
237 if (empty($error) && $filenamefrom != $filenameto) {
243 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
244 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
245 $publicmediasdirwithslash .=
'/';
248 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
249 $filenameto .=
'.noexe';
253 if ($filenamefrom && $filenameto) {
254 $srcpath = $upload_dir.
'/'.$filenamefrom;
255 $destpath = $upload_dir.
'/'.$filenameto;
257 $reshook = $hookmanager->initHooks(array(
'actionlinkedfiles'));
258 $parameters = array(
'filenamefrom' => $filenamefrom,
'filenameto' => $filenameto,
'upload_dir' => $upload_dir);
259 $reshook = $hookmanager->executeHooks(
'renameUploadedFile', $parameters, $object);
261 if (empty($reshook)) {
262 if (preg_match(
'/^\./', $filenameto)) {
263 $langs->load(
"errors");
264 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
265 } elseif (!file_exists($destpath)) {
266 $result =
dol_move($srcpath, $destpath);
273 if (
GETPOST(
'modulepart',
'aZ09') ==
'medias') {
277 if ($generatethumbs) {
278 if ($object->id > 0) {
280 $object->addThumbs($destpath);
283 $object->delThumbs($srcpath);
289 $langs->load(
"errors");
290 setEventMessages($langs->trans(
"ErrorFailToRenameFile", $filenamefrom, $filenameto),
null,
'errors');
293 $langs->load(
"errors");
294 setEventMessages($langs->trans(
"ErrorDestinationAlreadyExists", $filenameto),
null,
'errors');
302 if (
GETPOST(
'ecmfileid',
'int') > 0) {
303 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
305 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
307 $result = $ecmfile->fetch(
GETPOST(
'ecmfileid',
'int'));
310 if (empty($ecmfile->share)) {
311 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
315 $ecmfile->share =
'';
317 $result = $ecmfile->update($user);
Class to manage ECM files.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
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, $donotupdatesession=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_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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.