31 if (
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 paramater $permissiontoadd as not set before.');
45 print
'The file actions_linkedfiles.inc.php was included but paramater $permissiontoadd as not set before.';
51 if (
GETPOST(
'sendit',
'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC) && !empty($permissiontoadd)) {
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) && !empty($conf->global->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);
89 } elseif (
GETPOST(
'linkit',
'restricthtml') && !empty($conf->global->MAIN_UPLOAD_DOC) && !empty($permissiontoadd)) {
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;
101 if ($action ==
'confirm_deletefile' && $confirm ==
'yes' && !empty($permissiontoadd)) {
102 $urlfile =
GETPOST(
'urlfile',
'alpha', 0,
null,
null, 1);
103 if (
GETPOST(
'section',
'alpha')) {
105 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
108 $urlfile = basename($urlfile);
109 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
110 if (!empty($upload_dirold)) {
111 $fileold = $upload_dirold.
"/".$urlfile;
114 $linkid =
GETPOST(
'linkid',
'int');
118 $dir = dirname($file).
'/';
119 $dirthumb = $dir.
'/thumbs/';
121 $ret =
dol_delete_file($file, 0, 0, 0, (is_object($object) ? $object :
null));
122 if (!empty($fileold)) {
123 dol_delete_file($fileold, 0, 0, 0, (is_object($object) ? $object :
null));
129 if (preg_match(
'/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i', $file, $regs)) {
130 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_small'.$regs[0]);
131 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
135 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_mini'.$regs[0]);
136 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
142 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $urlfile),
null,
'errors');
145 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
146 $link =
new Link($db);
147 $link->fetch($linkid);
148 $res = $link->delete($user);
150 $langs->load(
'link');
152 setEventMessages($langs->trans(
"LinkRemoved", $link->label),
null,
'mesgs');
154 if (count($link->errors)) {
157 setEventMessages($langs->trans(
"ErrorFailedToDeleteLink", $link->label),
null,
'errors');
162 if (is_object($object) && $object->id > 0) {
164 header(
'Location: '.$backtopage);
167 $tmpurl = $_SERVER[
"PHP_SELF"].
'?id='.$object->id.(GETPOST(
'section_dir',
'alpha') ?
'§ion_dir='.urlencode(
GETPOST(
'section_dir',
'alpha')) :
'').(!empty($withproject) ?
'&withproject=1' :
'');
168 header(
'Location: '.$tmpurl);
172 } elseif ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha') && !empty($permissiontoadd)) {
173 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
174 $langs->load(
'link');
175 $link =
new Link($db);
176 $f = $link->fetch(
GETPOST(
'linkid',
'int'));
178 $link->url =
GETPOST(
'link',
'alpha');
179 if (substr($link->url, 0, 7) !=
'http://' && substr($link->url, 0, 8) !=
'https://' && substr($link->url, 0, 7) !=
'file://') {
180 $link->url =
'http://'.$link->url;
182 $link->label =
GETPOST(
'label',
'alphanohtml');
183 $res = $link->update($user);
185 setEventMessages($langs->trans(
"ErrorFailedToUpdateLink", $link->label),
null,
'mesgs');
190 } elseif ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha') && !empty($permissiontoadd)) {
192 if (!empty($upload_dir)) {
199 if (preg_match(
'/__.*__/', $filenameto)) {
203 if (!$error && $filenamefrom != $filenameto) {
209 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
210 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
211 $publicmediasdirwithslash .=
'/';
214 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
215 $filenameto .=
'.noexe';
219 if ($filenamefrom && $filenameto) {
220 $srcpath = $upload_dir.
'/'.$filenamefrom;
221 $destpath = $upload_dir.
'/'.$filenameto;
223 $reshook = $hookmanager->initHooks(array(
'actionlinkedfiles'));
224 $parameters = array(
'filenamefrom' => $filenamefrom,
'filenameto' => $filenameto,
'upload_dir' => $upload_dir);
225 $reshook = $hookmanager->executeHooks(
'renameUploadedFile', $parameters, $object);
227 if (empty($reshook)) {
228 if (preg_match(
'/^\./', $filenameto)) {
229 $langs->load(
"errors");
230 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
231 } elseif (!file_exists($destpath)) {
232 $result =
dol_move($srcpath, $destpath);
239 if (
GETPOST(
'modulepart') ==
'medias') {
243 if ($generatethumbs) {
245 $object->addThumbs($destpath);
254 $langs->load(
"errors");
255 setEventMessages($langs->trans(
"ErrorFailToRenameFile", $filenamefrom, $filenameto),
null,
'errors');
258 $langs->load(
"errors");
259 setEventMessages($langs->trans(
"ErrorDestinationAlreadyExists", $filenameto),
null,
'errors');
267 if (
GETPOST(
'ecmfileid',
'int') > 0) {
268 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
270 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
272 $result = $ecmfile->fetch(
GETPOST(
'ecmfileid',
'int'));
275 if (empty($ecmfile->share)) {
276 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
280 $ecmfile->share =
'';
282 $result = $ecmfile->update($user);