Пример #1
0
 /**
  * 上传
  */
 public function uploadAction()
 {
     $file = $_FILES['filedata'];
     $data = array();
     if (empty($file['name'])) {
         return $this->json(false, $this->lang['file_upload_null'], false, false);
     }
     if (is_uploaded_file($file['tmp_name'])) {
         if ($file['size'] > $this->options['upload']['sizelimit']) {
             return $this->json(false, sprintf($this->lang['file_too_large'], $file['name'], $file['size']), false, false);
         }
         $mime = $this->_getMime($file);
         if ($enables = $this->_request->getParam('enables')) {
             if (!in_array($mime, $this->_enableMimes[$enables])) {
                 return $this->json(false, $this->lang['invalid_file_type'], false, false);
             }
         }
         $mod = $this->_request->getParam('mod', self::UPLOAD_ATTACHMENT);
         if (!in_array($mod, $this->_supportMod)) {
             $mod = self::UPLOAD_ATTACHMENT;
         }
         $fileId = $mod == self::UPLOAD_ATTACHMENT ? Dao_Td_Attachment_File::getFileId() : Dao_Td_Netdisk_File::getFileId();
         $path = $mod . '/' . substr($fileId, 0, 1);
         $filePath = $this->options['upload']['path'] . '/' . $path;
         if (!is_dir($filePath)) {
             mkdir($filePath, 0777, true);
         }
         $params = array('fileid' => $fileId, 'filename' => $file['name'], 'size' => $file['size'], 'type' => $mime, 'path' => $path, 'uniqueid' => $this->_user->uniqueId, 'orgid' => $this->_user->orgId);
         if ($mod == self::UPLOAD_NETDISK) {
             $params['folderid'] = $this->_request->getParam('folderid', '^root');
             /* @var $daoFile Dao_Td_Netdisk_File */
             $daoFile = $this->getDao('Dao_Td_Netdisk_File');
         } else {
             /* @var $daoFile Dao_Td_Attachment_File */
             $daoFile = $this->getDao('Dao_Td_Attachment_File');
         }
         $ret = $daoFile->createFile($params);
         if ($mod == self::UPLOAD_NETDISK && $ret == -1) {
             return $this->json(false, $this->lang['space_not_enough'], false, false);
         }
         if (!$ret) {
             return $this->json(false, sprintf($this->lang['file_upload_failure'], $file['name']), false, false);
         }
         $ret = @move_uploaded_file($file['tmp_name'], $filePath . '/' . $fileId);
         if (!$ret) {
             return $this->json(false, sprintf($this->lang['file_upload_failure'], $file['name']), false, false);
         }
         $data['fileid'] = $fileId;
         $format = $this->_request->getParam('format', 'json');
         if ($format == 'script') {
             $data['success'] = true;
             $data['message'] = 'success';
             return $this->script($data);
         } else {
             return $this->json(true, $this->lang['file_upload_success'], $data, false);
         }
     }
     $this->json(false, sprintf($this->lang['file_upload_failure'], $file['name']), false, false);
 }
Пример #2
0
 /**
  * 删除关联附件
  *
  * @param string $tuduId
  * @param string $postId
  * @return boolean
  */
 public function deleteAttachment($tuduId, $postId)
 {
     return $this->_fileDao->deletePost($tuduId, $postId);
 }