Beispiel #1
0
 private function onAdd()
 {
     $form = $this->formAdd();
     if (false !== ($error = $form->validate($this->module))) {
         return $error . $this->templateAdd();
     }
     $file = $form->getVar('file');
     $tmp = $file['tmp_name'];
     $postid = $this->post->getID();
     $userid = GWF_Session::getUserID();
     $options = 0;
     $options |= isset($_POST['guest_view']) ? GWF_ForumAttachment::GUEST_VISIBLE : 0;
     $options |= isset($_POST['guest_down']) ? GWF_ForumAttachment::GUEST_DOWNLOAD : 0;
     # Put in db
     $attach = new GWF_ForumAttachment(array('fatt_aid' => 0, 'fatt_uid' => $userid, 'fatt_pid' => $postid, 'fatt_mime' => GWF_Upload::getMimeType($tmp), 'fatt_size' => filesize($tmp), 'fatt_downloads' => 0, 'fatt_filename' => $file['name'], 'fatt_options' => $options, 'fatt_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND)));
     if (false === $attach->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $aid = $attach->getID();
     # Copy file
     $path = $attach->dbimgPath();
     if (false === GWF_Upload::moveTo($file, $path)) {
         @unlink($tmp);
         return GWF_HTML::err('ERR_WRITE_FILE', $path);
     }
     @unlink($tmp);
     $this->post->increase('post_attachments', 1);
     return $this->module->message('msg_attach_added', array($this->post->getShowHREF()));
 }
Beispiel #2
0
 private function unReUpload(array $file, GWF_ForumAttachment $attach)
 {
     $temp = $file['tmp_name'];
     $target = $attach->dbimgPath();
     $success = GWF_Upload::moveTo($file, $target);
     @unlink($temp);
     if (!$success) {
         return GWF_HTML::err('ERR_WRITE_FILE', $target);
     }
     if (false === $attach->saveVars(array('fatt_mime' => GWF_Upload::getMimeType($target), 'fatt_size' => filesize($target), 'fatt_downloads' => 0, 'fatt_filename' => $file['name'], 'fatt_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND)))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return false;
 }
Beispiel #3
0
 private function templateAttach(GWF_ForumAttachment $attach, GWF_ForumPost $post, $user)
 {
     $path = $attach->dbimgPath();
     $mime = $attach->getVar('fatt_mime');
     $as_attach = !$attach->isImage();
     $filename = $as_attach ? $attach->getVar('fatt_filename') : true;
     if ($as_attach) {
         $attach->increase('fatt_downloads', 1);
     }
     GWF_Upload::outputFile($path, $as_attach, $mime, $filename);
     die;
 }
Beispiel #4
0
 public function getAttachments()
 {
     return GWF_ForumAttachment::getAttachments($this->getID());
 }