/** * Moves the temporary file to its final destination. * * Michael Klier <*****@*****.**> */ function _media_upload_action($data) { global $conf; if (is_array($data) && count($data) === 5) { io_createNamespace($data[2], 'media'); if (rename($data[0], $data[1])) { chmod($data[1], $conf['fmode']); media_notify($data[2], $data[1], $data[3]); // add a log entry to the media changelog if ($data[4]) { addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_EDIT); } else { addMediaLogEntry(time(), $data[2], DOKU_CHANGE_TYPE_CREATE); } return $data[2]; } else { return new IXR_ERROR(1, 'Upload failed.'); } } else { return new IXR_ERROR(1, 'Upload failed.'); } }
/** * Saves an uploaded media file * * @author Andreas Gohr <*****@*****.**> * @author Michael Klier <*****@*****.**> */ function media_upload_finish($fn_tmp, $fn, $id, $imime, $overwrite) { global $conf; global $lang; // prepare directory io_createNamespace($id, 'media'); if (move_uploaded_file($fn_tmp, $fn)) { // Set the correct permission here. // Always chmod media because they may be saved with different permissions than expected from the php umask. // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) chmod($fn, $conf['fmode']); msg($lang['uploadsucc'], 1); media_notify($id, $fn, $imime); // add a log entry to the media changelog if ($overwrite) { addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_EDIT); } else { addMediaLogEntry(time(), $id, DOKU_CHANGE_TYPE_CREATE); } return $id; } else { msg($lang['uploadfail'], -1); } }
/** * Moves the current version of media file to the media_attic * directory * * @author Kate Arzamastseva <*****@*****.**> * @param string $id * @return int - revision date */ function media_saveOldRevision($id) { global $conf, $lang; $oldf = mediaFN($id); if (!@file_exists($oldf)) { return ''; } $date = filemtime($oldf); if (!$conf['mediarevisions']) { return $date; } $medialog = new MediaChangeLog($id); if (!$medialog->getRevisionInfo($date)) { // there was an external edit, // there is no log entry for current version of file if (!@file_exists(mediaMetaFN($id, '.changes'))) { addMediaLogEntry($date, $id, DOKU_CHANGE_TYPE_CREATE, $lang['created']); } else { addMediaLogEntry($date, $id, DOKU_CHANGE_TYPE_EDIT); } } $newf = mediaFN($id, $date); io_makeFileDir($newf); if (copy($oldf, $newf)) { // Set the correct permission here. // Always chmod media because they may be saved with different permissions than expected from the php umask. // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) chmod($newf, $conf['fmode']); } return $date; }
public function handle() { global $conf, $ID; //$this->_debug_print_r($data); //$this->_debug_print_r($_REQUEST); //If delete requested if(isset($_REQUEST['media_id_to_delete'])){ if(checkSecurityToken($_REQUEST['sectok'])){ $mediaToDelete = $_REQUEST['media_id_to_delete']; $file = mediaFN($mediaToDelete); if(file_exists($file)){ if(media_inuse($mediaToDelete)===false){ // trigger an event - MEDIA_DELETE_FILE $data['id'] = $mediaToDelete; $data['name'] = basename($file); $data['path'] = $file; $data['size'] = (@file_exists($file)) ? filesize($file) : 0; $data['unl'] = false; $data['del'] = false; $evt = new Doku_Event('MEDIA_DELETE_FILE',$data); if ($evt->advise_before()) { $data['unl'] = @unlink($file); if($data['unl']){ addMediaLogEntry(time(), $mediaToDelete, DOKU_CHANGE_TYPE_DELETE); $data['del'] = io_sweepNS($mediaToDelete,'mediadir'); } } $evt->advise_after(); unset($evt); $this->ok = sprintf($this->getLang('delete_file_ok'),$mediaToDelete); ; }else{ $this->error = sprintf($this->getLang('delete_file_in_use'),$mediaToDelete); } }else{ $this->error = sprintf($this->getLang('delete_file_not_found'),$mediaToDelete); } }//end of csrf check } //Searching for orphaned medias $data = array(); //getting all medias search($data,$conf['mediadir'],'search_media', array('showmsg'=>true,'depth'=>500),str_replace(':', '/', getNS($ID))); //check if they are (still) in use or not. foreach($data as $media){ $isUsed = media_inuse($media['id']); if($isUsed === false){ $this->orphans_medias[$media['id']] = $media; } } }