Esempio n. 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()));
 }
Esempio n. 2
0
 private function onReup(GWF_Download $dl)
 {
     $form = $this->getFormReup($dl);
     if (false !== ($err = $form->validate($this->module))) {
         return $err . $this->templateEdit($dl);
     }
     if (false === ($file = $form->getVar('file'))) {
         return $this->module->error('err_file') . $this->templateEdit($dl);
     }
     if ($this->module->isModerated($this->module)) {
         return GWF_HTML::err('ERR_NO_PERMISSION') . $this->templateEdit($dl);
     }
     $tempname = 'dbimg/dl/' . $dl->getVar('dl_id');
     if (false === ($file = GWF_Upload::moveTo($file, $tempname))) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($tempname)) . $this->templateEdit($dl);
     }
     if (false === $dl->saveVars(array('dl_uid' => GWF_Session::getUserID(), 'dl_mime' => GWF_Upload::getMimeType($file['tmp_name']), 'dl_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND)))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_uploaded') . $this->templateEdit($dl);
 }
Esempio n. 3
0
 private function onAdd()
 {
     $form = $this->getForm();
     if (false !== ($errors = $form->validate($this->module))) {
         return $errors . $this->templateAdd();
     }
     if (false === ($file = $this->getFile())) {
         $this->uploadedFile($form);
         $file = $form->getVar('file');
     }
     $tempname = $file['tmp_name'];
     if (!file_exists($tempname)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd();
     }
     $mod = $this->module->isModerated($this->module);
     $userid = GWF_Session::getUserID();
     $options = 0;
     $options |= isset($_POST['adult']) ? GWF_Download::ADULT : 0;
     $options |= isset($_POST['huname']) ? GWF_Download::HIDE_UNAME : 0;
     $options |= isset($_POST['guest_view']) ? GWF_Download::GUEST_VISIBLE : 0;
     $options |= isset($_POST['guest_down']) ? GWF_Download::GUEST_DOWNLOAD : 0;
     $options |= $mod ? 0 : GWF_Download::ENABLED;
     $dl = new GWF_Download(array('dl_id' => 0, 'dl_uid' => $userid, 'dl_gid' => $form->getVar('group'), 'dl_level' => $form->getVar('level'), 'dl_token' => GWF_Download::generateToken(), 'dl_count' => 0, 'dl_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'dl_filename' => $form->getVar('filename'), 'dl_realname' => $file['name'], 'dl_descr' => $form->getVar('descr'), 'dl_mime' => GWF_Upload::getMimeType($file['tmp_name']), 'dl_price' => sprintf('%.02f', $form->getVar('price', 0.0)), 'dl_options' => $options, 'dl_voteid' => 0, 'dl_purchases' => 0, 'dl_expire' => GWF_TimeConvert::humanToSeconds($form->getVar('expire'))));
     if (false === $dl->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd();
     }
     $dlid = $dl->getID();
     $filename = 'dbimg/dl/' . $dlid;
     if (false === GWF_Upload::moveTo($file, $filename)) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($filename)) . $this->templateAdd();
     }
     if (false === @unlink($tempname)) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($tempname)) . $this->templateAdd();
     }
     if (false === $dl->createVotes($this->module)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd();
     }
     $this->clearFile();
     if ($mod) {
         $this->sendModMail($dl);
         return $this->module->message('msg_uploaded_mod');
     }
     return $this->module->message('msg_uploaded');
 }
Esempio n. 4
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;
 }