/** * storeUpload. */ public function storeUpload($name, $filename) { $this->time->start(); $return = parent::storeUpload($name, $filename); $time = $this->time->stop(); $this->log(array('type' => 'storeUpload', 'name' => $name, 'filename' => $filename, 'time' => $time)); return $return; }
/** * 云存储文件 * * @param string $fieldName * 上传表单字段的名称 * @return array 返回上传文件成功后的object * * object结构如下: * array( * ['_id'] => * MongoId( * * $id = * '537cc9b54896194b228b4581' * ) * ['collection_id'] => * NULL * ['name'] => * 'b21c8701a18b87d624ac8e2d050828381f30fd11.jpg' * ['type'] => * 'image/jpeg' * ['tmp_name'] => * '/tmp/phpeBS799' * ['error'] => * 0 * ['size'] => * 350522 * ['mime'] => * 'image/jpeg; charset=binary' * ['filename'] => * 'b21c8701a18b87d624ac8e2d050828381f30fd11.jpg' * ['uploadDate'] => * MongoDate( * * sec = * 1400687029 * usec = * 515000 * ) * ['length'] => * 350522 * ['chunkSize'] => * 262144 * ['md5'] => * '3a736c4eed22030dde16df11fee263e7' * ) * */ public function storeToGridFS($fieldName, $metadata = array()) { if (!is_array($metadata)) { $metadata = array(); } if (!isset($_FILES[$fieldName])) { throw new \Exception('$_FILES[$fieldName]无效'); } $metadata = array_merge($metadata, $_FILES[$fieldName]); $finfo = new \finfo(FILEINFO_MIME); $mime = $finfo->file($_FILES[$fieldName]['tmp_name']); if ($mime !== false) { $metadata['mime'] = $mime; } $id = $this->_fs->storeUpload($fieldName, $metadata); $gridfsFile = $this->_fs->get($id); if (!$gridfsFile instanceof \MongoGridFSFile) { fb($gridfsFile, 'LOG'); throw new \Exception('$gridfsFile is not instanceof MongoGridFSFile'); } return $gridfsFile->file; }