Esempio n. 1
0
 /**
  * Uploads a file to a given directory and returns an attachment string
  * that is appended to report/comment bodies
  *
  * @param   integer  $thread_id  Directory to upload files to
  * @param   integer  $post_id    Post ID
  * @return  boolean
  */
 public function uploadTask($thread_id, $post_id)
 {
     if (!$thread_id) {
         $this->setError(Lang::txt('COM_FORUM_NO_UPLOAD_DIRECTORY'));
         return false;
     }
     // Instantiate an attachment record
     $attachment = Attachment::oneOrNew(Request::getInt('attachment', 0));
     $attachment->set('description', trim(Request::getVar('description', '')));
     $attachment->set('parent', $thread_id);
     $attachment->set('post_id', $post_id);
     if ($attachment->isNew()) {
         $attachment->set('state', 1);
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file || !isset($file['name']) || !$file['name']) {
         if ($attachment->get('id')) {
             // Only updating the description
             if (!$attachment->save()) {
                 $this->setError($attachment->getError());
                 return false;
             }
         }
         return true;
     }
     // Upload file
     if (!$attachment->upload($file['name'], $file['tmp_name'])) {
         $this->setError($attachment->getError());
     }
     // Save entry
     if (!$attachment->save()) {
         $this->setError($attachment->getError());
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Uploads a file to a given directory and returns an attachment string
  * that is appended to report/comment bodies
  *
  * @param   integer  $thread_id  Directory to upload files to
  * @param   integer  $post_id    Post ID
  * @return  boolean
  */
 public function upload($thread_id, $post_id)
 {
     // Check if they are logged in
     if (User::isGuest()) {
         return false;
     }
     if (!$thread_id) {
         $this->setError(Lang::txt('PLG_COURSES_DISCUSSIONS_NO_UPLOAD_DIRECTORY'));
         return false;
     }
     // Instantiate an attachment record
     $attachment = Attachment::oneOrNew(Request::getInt('attachment', 0));
     $attachment->set('description', trim(Request::getVar('description', '')));
     $attachment->set('parent', $thread_id);
     $attachment->set('post_id', $post_id);
     if ($attachment->isNew()) {
         $attachment->set('state', Attachment::STATE_PUBLISHED);
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file || !isset($file['name']) || !$file['name']) {
         if ($attachment->get('id')) {
             // Only updating the description
             if (!$attachment->save()) {
                 $this->setError($attachment->getError());
                 return false;
             }
         }
         return true;
     }
     // Upload file
     if (!$attachment->upload($file['name'], $file['tmp_name'])) {
         $this->setError($attachment->getError());
     }
     // Save entry
     if (!$attachment->save()) {
         $this->setError($attachment->getError());
     }
     return true;
 }