Exemplo n.º 1
0
 /**
  * 上传帖子图片(正常的附件目录)
  * 
  * @param mixed $uid        Description.
  * @param mixed $allowValue Description.
  *
  * @access private
  *
  * @return mixed Value.
  */
 private function _uploadAttach($uid, $allowValue)
 {
     global $_G;
     $fileExtension = FileUtils::getFileExtension($_FILES['uploadFile']['name'][$allowValue], 'jpg');
     $type = 'forum';
     $extid = 0;
     $forcename = '';
     Yii::import('application.components.discuz.source.class.discuz.discuz_upload', true);
     $upload = new Mobcent_upload();
     $attach['extension'] = $fileExtension;
     $attach['attachdir'] = $upload->get_target_dir($type, $extid);
     $filename = $upload->get_target_filename($type, $extid, $forcename) . '.' . $attach['extension'];
     $attach['attachment'] = $attach['attachdir'] . $filename;
     $attach['target'] = getglobal('setting/attachdir') . './' . $type . '/' . $attach['attachment'];
     $savePath = getglobal('setting/attachdir') . './' . $type . '/' . $attach['attachdir'];
     if (!is_dir($savePath)) {
         mkdir($savePath, 0777, true);
     }
     $remote = $width = $thumb = 0;
     $res = array();
     $saveName = $savePath . $filename;
     if (move_uploaded_file($_FILES['uploadFile']['tmp_name'][$allowValue], $saveName)) {
         $aid = getattachnewaid($uid);
         $img_info = getimagesize($attach['target']);
         $size = filesize($attach['target']);
         $insert = array('aid' => $aid, 'dateline' => $_G['timestamp'], 'filename' => $filename, 'filesize' => $size, 'attachment' => $attach['attachment'], 'isimage' => 1, 'uid' => $uid, 'thumb' => $thumb, 'remote' => $remote, 'width' => $img_info[0]);
         C::t('forum_attachment_unused')->insert($insert);
         // 添加水印
         Yii::import('application.components.discuz.source.class.class_image', true);
         $image = new Mobcent_Image();
         if ($image->param['watermarkstatus']['forum'] > 0) {
             $image->makeWatermark($attach['target'], '', 'forum');
         }
         $path_url = ImageUtils::getAttachUrl() . '/' . $type . '/' . $attach['attachment'];
         ImageUtils::getThumbImageEx($path_url, 10, false, false, true);
         $res['id'] = $aid;
         $res['urlName'] = $path_url;
     }
     return $res;
 }
Exemplo n.º 2
0
 private static function _getThumbTempFile($image)
 {
     $tempFileName = md5($image);
     $fileExt = FileUtils::getFileExtension($image, 'jpg');
     strlen($fileExt) > 5 && ($fileExt = 'jpg');
     $tempFileName .= '.' . $fileExt;
     return $tempFileName;
 }
Exemplo n.º 3
0
Arquivo: db.php Projeto: demental/m
 /**
  * Helper method to store the file
  */
 protected function _upFile($obj, $field, $relativePathFromUploadFolder, $prefix = null)
 {
     if (is_null($prefix)) {
         $prefix = $obj->tableName();
     }
     if (is_uploaded_file($_FILES[$field]['tmp_name'])) {
         $ext = FileUtils::getFileExtension($_FILES[$field]['name']);
         $name = $prefix . "." . $ext;
         $destination = IMAGES_UPLOAD_FOLDER . $relativePathFromUploadFolder . '/' . $name;
         if (move_uploaded_file($_FILES[$field]["tmp_name"], $destination) && chmod($destination, 0644)) {
             return $name;
         }
     }
     return false;
 }
Exemplo n.º 4
0
Arquivo: T.php Projeto: demental/m
 private function getStringsFromfile($file, &$lngtb)
 {
     $extension = FileUtils::getFileExtension($file);
     $method = 'getStringsFrom' . $extension;
     if (!method_exists($this, $method)) {
         return;
     }
     $reflectionMethod = new ReflectionMethod('T', $method);
     $reflectionMethod->invokeArgs($this, array($file, &$lngtb));
 }
Exemplo n.º 5
0
 /**
  * 检测上传相关项
  * 
  * @param mixed $res  初始化数组.
  * @param mixed $file 上传的单个文件数组信息.
  *
  * @return mixed array.
  */
 public function checkUpload($res, $file)
 {
     // 文件上传失败,捕获错误代码
     if ($file['error']) {
         $res['errCode'] = 0;
         $res['errMsg'] = self::error($file['error']);
         return $res;
     }
     // 无效上传
     $file['name'] = strip_tags($file['name']);
     if (empty($file['name'])) {
         $res['errCode'] = 0;
         $res['errMsg'] = '未知上传错误!';
         return $res;
     }
     if (!is_uploaded_file($file['tmp_name'])) {
         $res['errCode'] = 0;
         $res['errMsg'] = '非法上传文件';
         return $res;
     }
     // 检查文件大小
     $maxSize = 2000000;
     if ($file['size'] > $maxSize || $file['size'] == 0) {
         $res['errCode'] = 0;
         $res['errMsg'] = '上传文件大小不符!';
         return $res;
     }
     // 检查文件Mime类型
     $mime = $file['type'];
     $allowMime = array('image/png', 'image/jpeg');
     if (!in_array(strtolower($mime), $allowMime)) {
         $res['errCode'] = 0;
         $res['errMsg'] = '上传文件MIME类型不允许!';
         return $res;
     }
     // 检查文件后缀
     $ext = FileUtils::getFileExtension($file['name'], 'jpg');
     $allowExt = array('jpg', 'png', 'jpeg');
     if (!in_array(strtolower($ext), $allowExt)) {
         $res['errCode'] = 0;
         $res['errMsg'] = '上传文件后缀不允许!';
         return $res;
     }
     // 通过检测
     $res['errCode'] = 1;
     return $res;
 }
Exemplo n.º 6
0
Arquivo: db.php Projeto: demental/m
 public function getFileFormat()
 {
     $args = func_get_args();
     if (is_a($args[0], 'DB_DataObject')) {
         $obj = $args[0];
         $field = null;
     } else {
         $obj = $args[1];
         $field = $args[0];
     }
     $info = $obj->_getPluginsDef();
     $info = $info['upload'];
     if (is_null($field)) {
         $field = array_keys($info);
         $field = $field[0];
         $info = array_shift($info);
     } else {
         $info = $info[$field];
     }
     return self::returnStatus(FileUtils::getFileExtension($obj->{$field}));
 }