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){
46 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")), null,
'errors');
55 if (
GETPOST(
'section_dir')) $generatethumbs=0;
57 if (! empty($upload_dirold) && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
61 elseif (! empty($upload_dir))
68 elseif (
GETPOST(
'linkit',
'none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
70 $link =
GETPOST(
'link',
'alpha');
73 if (substr($link, 0, 7) !=
'http://' && substr($link, 0, 8) !=
'https://' && substr($link, 0, 7) !=
'file://') {
74 $link =
'http://' . $link;
82 if ($action ==
'confirm_deletefile' && $confirm ==
'yes')
84 $urlfile =
GETPOST(
'urlfile',
'alpha', 0, null, null, 1);
85 if (
GETPOST(
'section',
'alpha'))
87 $file = $upload_dir . (preg_match(
'/\/$/', $upload_dir) ?
'' :
'/') . $urlfile;
91 $urlfile=basename($urlfile);
92 $file = $upload_dir . (preg_match(
'/\/$/', $upload_dir) ?
'' :
'/') . $urlfile;
93 if (! empty($upload_dirold)) $fileold = $upload_dirold .
"/" . $urlfile;
95 $linkid =
GETPOST(
'linkid',
'int');
99 $dir = dirname($file).
'/';
100 $dirthumb = $dir.
'/thumbs/';
102 $ret =
dol_delete_file($file, 0, 0, 0, (is_object($object)?$object:null));
103 if (! empty($fileold))
dol_delete_file($fileold, 0, 0, 0, (is_object($object)?$object:null));
106 if (preg_match(
'/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs))
108 $photo_vignette=basename(preg_replace(
'/'.$regs[0].
'/i',
'',$file).
'_small'.$regs[0]);
109 if (file_exists(
dol_osencode($dirthumb.$photo_vignette)))
114 $photo_vignette=basename(preg_replace(
'/'.$regs[0].
'/i',
'',$file).
'_mini'.$regs[0]);
115 if (file_exists(
dol_osencode($dirthumb.$photo_vignette)))
121 if ($ret)
setEventMessages($langs->trans(
"FileWasRemoved", $urlfile), null,
'mesgs');
122 else setEventMessages($langs->trans(
"ErrorFailToDeleteFile", $urlfile), null,
'errors');
126 require_once DOL_DOCUMENT_ROOT .
'/core/class/link.class.php';
127 $link =
new Link($db);
130 $res = $link->delete($user);
132 $langs->load(
'link');
134 setEventMessages($langs->trans(
"LinkRemoved", $link->label), null,
'mesgs');
136 if (count($link->errors)) {
139 setEventMessages($langs->trans(
"ErrorFailedToDeleteLink", $link->label), null,
'errors');
144 if (is_object($object) && $object->id > 0)
148 header(
'Location: ' . $backtopage);
153 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(GETPOST(
'section_dir',
'alpha')?
'§ion_dir='.urlencode(
GETPOST(
'section_dir',
'alpha')):
'').(!empty($withproject)?
'&withproject=1':
''));
158 elseif ($action ==
'confirm_updateline' &&
GETPOST(
'save',
'alpha') &&
GETPOST(
'link',
'alpha'))
160 require_once DOL_DOCUMENT_ROOT .
'/core/class/link.class.php';
161 $langs->load(
'link');
162 $link =
new Link($db);
163 $link->id =
GETPOST(
'linkid',
'int');
167 $link->url =
GETPOST(
'link',
'alpha');
168 if (substr($link->url, 0, 7) !=
'http://' && substr($link->url, 0, 8) !=
'https://' && substr($link->url, 0, 7) !=
'file://')
170 $link->url =
'http://' . $link->url;
172 $link->label =
GETPOST(
'label',
'alpha');
173 $res = $link->update($user);
176 setEventMessages($langs->trans(
"ErrorFailedToUpdateLink", $link->label), null,
'mesgs');
184 elseif ($action ==
'renamefile' &&
GETPOST(
'renamefilesave',
'alpha'))
187 if (! empty($upload_dir))
192 if ($filenamefrom != $filenameto)
197 if (preg_match(
'/\.htm|\.html|\.php|\.pl|\.cgi$/i',$filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
199 $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 (! file_exists($destpath))
215 $result =
dol_move($srcpath, $destpath);
223 if (
GETPOST(
'modulepart') ==
'medias') $generatethumbs=0;
229 $object->addThumbs($destpath);
240 $langs->load(
"errors");
241 setEventMessages($langs->trans(
"ErrorFailToRenameFile", $filenamefrom, $filenameto), null,
'errors');
246 $langs->load(
"errors");
247 setEventMessages($langs->trans(
"ErrorDestinationAlreadyExists", $filenameto), null,
'errors');
255 if (
GETPOST(
'ecmfileid',
'int') > 0)
257 $shareenabled =
GETPOST(
'shareenabled',
'alpha');
259 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
261 $result = $ecmfile->fetch(
GETPOST(
'ecmfileid',
'int'));
266 if (empty($ecmfile->share))
268 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
274 $ecmfile->share =
'';
276 $result = $ecmfile->update($user);
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1)
Get and save an upload file (for example after submitting a new file a mail form).
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)
Return a generated password using default module.
Class to manage ECM files.