30 if (
GETPOST(
'sendit',
'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC))
34 if (is_array($_FILES[
'userfile'][
'tmp_name'])) $userfiles = $_FILES[
'userfile'][
'tmp_name'];
35 else $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
37 foreach ($userfiles as $key => $userfile)
39 if (empty($_FILES[
'userfile'][
'tmp_name'][$key]))
42 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
45 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")), null,
'errors');
54 if (
GETPOST(
'section_dir',
'alpha')) $generatethumbs = 0;
55 $allowoverwrite = (
GETPOST(
'overwritefile',
'int') ? 1 : 0);
57 if (!empty($upload_dirold) && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
59 $result =
dol_add_file_process($upload_dirold, $allowoverwrite, 1,
'userfile',
GETPOST(
'savingdocmask',
'alpha'), null,
'', $generatethumbs, $object);
60 } elseif (!empty($upload_dir))
62 $result =
dol_add_file_process($upload_dir, $allowoverwrite, 1,
'userfile',
GETPOST(
'savingdocmask',
'alpha'), null,
'', $generatethumbs, $object);
66 } elseif (
GETPOST(
'linkit',
'restricthtml') && !empty($conf->global->MAIN_UPLOAD_DOC))
68 $link =
GETPOST(
'link',
'alpha');
71 if (substr($link, 0, 7) !=
'http://' && substr($link, 0, 8) !=
'https://' && substr($link, 0, 7) !=
'file://') {
72 $link =
'http://'.$link;
80 if ($action ==
'confirm_deletefile' && $confirm ==
'yes')
82 $urlfile =
GETPOST(
'urlfile',
'alpha', 0, null, null, 1);
83 if (
GETPOST(
'section',
'alpha')) {
85 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
88 $urlfile = basename($urlfile);
89 $file = $upload_dir.(preg_match(
'/\/$/', $upload_dir) ?
'' :
'/').$urlfile;
90 if (!empty($upload_dirold)) $fileold = $upload_dirold.
"/".$urlfile;
92 $linkid =
GETPOST(
'linkid',
'int');
96 $dir = dirname($file).
'/';
97 $dirthumb = $dir.
'/thumbs/';
99 $ret =
dol_delete_file($file, 0, 0, 0, (is_object($object) ? $object : null));
100 if (!empty($fileold))
dol_delete_file($fileold, 0, 0, 0, (is_object($object) ? $object : null));
104 if (preg_match(
'/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i', $file, $regs))
106 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_small'.$regs[0]);
107 if (file_exists(
dol_osencode($dirthumb.$photo_vignette)))
112 $photo_vignette = basename(preg_replace(
'/'.$regs[0].
'/i',
'', $file).
'_mini'.$regs[0]);
113 if (file_exists(
dol_osencode($dirthumb.$photo_vignette)))
122 setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $urlfile), null,
'errors');
125 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
126 $link =
new Link($db);
127 $link->fetch($linkid);
128 $res = $link->delete($user);
130 $langs->load(
'link');
132 setEventMessages($langs->trans(
"LinkRemoved", $link->label), null,
'mesgs');
134 if (count($link->errors)) {
137 setEventMessages($langs->trans(
"ErrorFailedToDeleteLink", $link->label), null,
'errors');
142 if (is_object($object) && $object->id > 0) {
144 header(
'Location: '.$backtopage);
147 $tmpurl =
$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(GETPOST(
'section_dir',
'alpha') ?
'§ion_dir='.urlencode(
GETPOST(
'section_dir',
'alpha')) :
'').(!empty($withproject) ?
'&withproject=1' :
'');
148 header(
'Location: '.$tmpurl);
152 } elseif ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha'))
154 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
155 $langs->load(
'link');
156 $link =
new Link($db);
157 $f = $link->fetch(
GETPOST(
'linkid',
'int'));
160 $link->url =
GETPOST(
'link',
'alpha');
161 if (substr($link->url, 0, 7) !=
'http://' && substr($link->url, 0, 8) !=
'https://' && substr($link->url, 0, 7) !=
'file://')
163 $link->url =
'http://'.$link->url;
165 $link->label =
GETPOST(
'label',
'alphanohtml');
166 $res = $link->update($user);
169 setEventMessages($langs->trans(
"ErrorFailedToUpdateLink", $link->label), null,
'mesgs');
174 } elseif ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha'))
177 if (!empty($upload_dir))
186 if ($filenamefrom != $filenameto)
194 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
195 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) $publicmediasdirwithslash .=
'/';
197 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
198 $filenameto .=
'.noexe';
202 if ($filenamefrom && $filenameto)
204 $srcpath = $upload_dir.
'/'.$filenamefrom;
205 $destpath = $upload_dir.
'/'.$filenameto;
207 $reshook = $hookmanager->initHooks(array(
'actionlinkedfiles'));
208 $parameters = array(
'filenamefrom' => $filenamefrom,
'filenameto' => $filenameto,
'upload_dir' => $upload_dir);
209 $reshook = $hookmanager->executeHooks(
'renameUploadedFile', $parameters, $object);
213 if (preg_match(
'/^\./', $filenameto)) {
214 $langs->load(
"errors");
215 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto), null,
'errors');
216 } elseif (!file_exists($destpath)) {
217 $result =
dol_move($srcpath, $destpath);
225 if (
GETPOST(
'modulepart') ==
'medias') $generatethumbs = 0;
231 $object->addThumbs($destpath);
240 $langs->load(
"errors");
241 setEventMessages($langs->trans(
"ErrorFailToRenameFile", $filenamefrom, $filenameto), null,
'errors');
244 $langs->load(
"errors");
245 setEventMessages($langs->trans(
"ErrorDestinationAlreadyExists", $filenameto), null,
'errors');
253 if (
GETPOST(
'ecmfileid',
'int') > 0)
255 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
257 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
259 $result = $ecmfile->fetch(
GETPOST(
'ecmfileid',
'int'));
264 if (empty($ecmfile->share))
266 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
270 $ecmfile->share =
'';
272 $result = $ecmfile->update($user);
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
print $_SERVER["PHP_SELF"]
Edit parameters.
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
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).
Class to manage ECM files.