本文整理汇总了PHP中Uploader::getLength方法的典型用法代码示例。如果您正苦于以下问题:PHP Uploader::getLength方法的具体用法?PHP Uploader::getLength怎么用?PHP Uploader::getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uploader
的用法示例。
在下文中一共展示了Uploader::getLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bp_upload
//.........这里部分代码省略.........
if(isset($_GET['offset'])) {
$offset=intval($_GET['offset']);
}else{
$this->response(ResponseType::ERROR_LACKPARAMS);
}
*/
$tempModel = new Models\Temp($this->user_id);
if (!$tempModel->getTemp($upload_id)) {
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_NOTEMP);
}
//追加文件碎片
if ($tempModel->tmp_source->length < $tempModel->size) {
if ($_FILES) {
foreach ($_FILES as $upfile) {
$in_path = $upfile['tmp_name'];
}
} else {
$in_path = 'php://input';
}
$tempModel->append($in_path, $offset, $length);
}
//验证临时文件完整性
$finish = FALSE;
if ($tempModel->tmp_source->length >= $tempModel->size) {
if ($tempModel->md5 && $tempModel->md5 == $tempModel->tmp_source->md5) {
$finish = TRUE;
} else {
$tempModel->destroy();
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_DAMAGETEMP);
}
}
if ($finish) {
$tmp_file = $tempModel->tmp_source->downBuffer();
//临时文件是否可访问
if ($tmp_file) {
$uploader = new Uploader();
$uploader->process($tmp_file, '', $tempModel->size, $tempModel->md5);
} else {
$tempModel->destroy();
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_NOTEMPSOURCE);
}
//不是音频类型
/*
if($tempModel->type==Uploader::FILETYPE_AUDIO && $uploader->getType() != Uploader::FILETYPE_AUDIO){
$tempModel->destroy();
$this->response(ResponseType::FILE_ERROR_AUDIOTYPE);
}
*/
//文件超过限制
if ($uploader->getLength() > Core::config('file_max_size')) {
$tempModel->destroy();
$this->response(ResponseType::FILE_ERROR_SIZELIMIT);
}
//上传临时文件成功否
$basedirModel = new Models\FileDirectory();
if (!$basedirModel->findOne($tempModel->basedir)) {
$this->response(ResponseType::FILE_ERROR_DIR_INVALID);
}
if ($tempModel->type == Uploader::FILETYPE_VIDEO) {
$ctrl_type = 2;
} elseif ($tempModel->type == Uploader::FILETYPE_AUDIO) {
$ctrl_type = 1;
} else {
$ctrl_type = 0;
}
$uploader->ctrl_type = $ctrl_type;
$uploader->filename = $tempModel->filename;
if ($fileModel = $basedirModel->makeFile($uploader)) {
$result['id'] = $fileModel->get_fid();
$result['src'] = $fileModel->geturi($result['id']);
$result['mime'] = $fileModel->mime;
$result['size'] = $fileModel->size;
$result['name'] = $fileModel->getFilename();
$result['uploaded'] = TRUE;
$tempModel->destroy();
if ($fileModel->thumb_id) {
$photoModel = new Models\Photo();
if ($photoModel->findOne($fileModel->thumb_id, array('width', 'height'))) {
$result['thumb']['id'] = $photoModel->get_pid();
$result['thumb']['md5'] = $photoModel->md5;
$result['thumb']['width'] = $photoModel->width;
$result['thumb']['height'] = $photoModel->height;
$result['thumb']['mime'] = $photoModel->mime;
$imgurls = $photoModel->geturi($fileModel->thumb_id, 130);
$result['thumb']['src'] = $imgurls[0];
}
}
$this->response(ResponseType::FILE_OK, '', $result);
} else {
$tempModel->destroy();
$this->response(ResponseType::FILE_ERROR_SERVER);
}
} else {
//需要继续上传文件碎片
$result['offset'] = $tempModel->tmp_source->length;
$result['uploaded'] = FALSE;
$this->response(ResponseType::PHOTO_BPUPLOAD_OK_CONTINUE, '', $result);
}
}
}
示例2: bp_upload
//.........这里部分代码省略.........
}
$tempModel = new Models\Temp($this->user_id);
$tempModel->md5 = strtolower($data['md5']);
$tempModel->size = intval($data['size']);
$tempModel->type = Uploader::FILETYPE_IMAGE;
//图片应用
$tempModel->cid = intval($data['category']);
$tempModel->filename = $data['filename'];
$photoModel = new Models\Photo();
$r = $photoModel->geturiByMD5(array($tempModel->md5), 130, TRUE);
//自己曾经上传过
if ($r[0] && $r[0]['id']) {
$result['id'] = $r[0]['id'];
$result['src'] = $r[0]['src'];
$result['md5'] = $tempModel->md5;
$result['uploaded'] = TRUE;
$this->response(ResponseType::PHOTO_BPUPLOAD_OK, '', $result);
} else {
if ($tempModel->create()) {
$result['upload_id'] = $tempModel->get_upload_id();
$result['offset'] = 0;
$result['uploaded'] = FALSE;
$this->response(ResponseType::PHOTO_BPUPLOAD_OK_CREATETEMP, '', $result);
}
}
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_CREATETEMP);
} else {
//上传第二步
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : NULL;
$length = isset($_GET['length']) ? intval($_GET['length']) : NULL;
/*
if(isset($_GET['offset'])) {
$offset=intval($_GET['offset']);
}else{
$this->response(ResponseType::ERROR_LACKPARAMS);
}
*/
$tempModel = new Models\Temp($this->user_id);
if (!$tempModel->getTemp($upload_id)) {
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_NOTEMP);
}
//追加文件碎片
if ($tempModel->tmp_source->length < $tempModel->size) {
if ($_FILES) {
foreach ($_FILES as $upfile) {
$in_path = $upfile['tmp_name'];
}
} else {
$in_path = 'php://input';
}
$tempModel->append($in_path, $offset, $length);
}
//验证临时文件完整性
$finish = FALSE;
if ($tempModel->tmp_source->length >= $tempModel->size) {
//if($tempModel->md5 && $tempModel->md5 == $tempModel->tmp_source->md5){
if ($tempModel->size == $tempModel->tmp_source->length) {
$finish = TRUE;
} else {
$tempModel->destroy();
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_DAMAGETEMP);
}
}
if ($finish) {
$tmp_file = $tempModel->tmp_source->downBuffer();
//临时文件是否可访问
if ($tmp_file) {
$uploader = new Uploader();
$uploader->process($tmp_file, '', $tempModel->size, $tempModel->md5);
} else {
$tempModel->destroy();
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_NOTEMPSOURCE);
}
//不是图片类型
if ($uploader->getType() !== Uploader::FILETYPE_IMAGE) {
$tempModel->destroy();
$this->response(ResponseType::PHOTO_ERROR_IMAGETYPE);
}
//文件超过5M
if ($uploader->getLength() > Core::config('photo_max_size')) {
$tempModel->destroy();
$this->response(ResponseType::PHOTO_ERROR_IMAGESIZE);
}
//上传临时文件成功否
if ($result = $this->_processUpload($uploader, $tempModel->cid)) {
$tempModel->destroy();
$result['uploaded'] = TRUE;
$this->response(ResponseType::PHOTO_BPUPLOAD_OK, '', $result);
} else {
$tempModel->destroy();
$this->response(ResponseType::PHOTO_BPUPLOAD_ERROR_SERVER);
}
} else {
//需要继续上传文件碎片
$result['offset'] = $tempModel->tmp_source->length;
$result['uploaded'] = FALSE;
$this->response(ResponseType::PHOTO_BPUPLOAD_OK_CONTINUE, '', $result);
}
}
}