本文整理汇总了PHP中UploadFile::uploadOne方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadFile::uploadOne方法的具体用法?PHP UploadFile::uploadOne怎么用?PHP UploadFile::uploadOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadFile
的用法示例。
在下文中一共展示了UploadFile::uploadOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runAddVideo
public function runAddVideo()
{
$Video = $_FILES[video];
$Image = $_FILES[image];
import('ORG.Net.UploadFile');
$upload = new UploadFile();
$upload->maxSize = 100000000000;
// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg', 'bmp');
// 设置附件上传类型
$upload->savePath = './Data/Image/';
// 设置附件上传目录
//上传图片
if (!($imageInfo = $upload->uploadOne($Image, $savePath = './Data/Image/'))) {
// 上传错误提示错误信息
$this->error($upload->getErrorMsg());
}
//上传视频
$upload->allowExts = array('flv', 'mp4', 'rmvb');
// 设置附件上传类型
if (!($videoInfo = $upload->uploadOne($Video, $savePath = './Data/Video/'))) {
// 上传错误提示错误信息
$this->error($upload->getErrorMsg());
}
$data = $_POST;
var_dump($data);
die;
$data['image'] = $imageInfo[0]['savename'];
$data['video'] = $videoInfo[0]['savename'];
$data['time'] = date('Y-m-d', strtotime("now"));
$data['author'] = 'admin';
if (M('video')->add($data)) {
$this->success('添加成功');
}
}
示例2: upload
/**
* 上传文件
* @param Array $filename 表单file控件的name属性
* @param String $type 上传文件类型
* @param Array $aOtherConfig 其他配置参数
* @return Array 上传成功返回文件保存信息,失败返回错误信息
*/
public function upload($filename = 'filename', $type = 'image', $aOtherConfig = array())
{
//上传文件配置
$aUploadConfig = array('image' => array('allowExts' => array('jpg', 'gif', 'png', 'jpeg'), 'maxSize' => 3145728, 'savePath' => C('TMPL_PARSE_STRING.__FILES__') . '/image/', 'basePath' => '/image/'), 'audio' => array('allowExts' => array('aac', 'mp3'), 'maxSize' => 3145728, 'savePath' => C('TMPL_PARSE_STRING.__FILES__') . '/audio/', 'basePath' => '/audio/'), 'face' => array('allowExts' => array('jpg', 'gif', 'png', 'jpeg'), 'maxSize' => 3145728, 'savePath' => C('TMPL_PARSE_STRING.__FILES__') . '/face/', 'basePath' => '/face/', 'thumb' => true, 'thumbMaxWidth' => '24,48,120', 'thumbMaxHeight' => '24,48,120', 'thumbSuffix' => '_24-24,_48-48,_120-120'));
$public_config = array('autoSub' => true, 'subType' => 'date', 'saveRule' => 'uniqid', 'thumbPrefix' => '');
$custom_config = $aUploadConfig[$type];
if (!empty($aOtherConfig)) {
$custom_config = array_merge($custom_config, $aOtherConfig);
}
$config = array_merge($public_config, $custom_config);
import('ORG.Net.UploadFile');
//引入上传类
$upload = new UploadFile($config);
//执行上传
$info = $upload->uploadOne($_FILES[$filename]);
//执行上传操作
if (!$info) {
// 上传错误提示错误信息
return array('status' => 1001, 'msg' => $upload->getErrorMsg());
} else {
// 上传成功 获取上传文件信息
$info = $info[0];
//添加数据库记录
$data = array('appid' => $this->oApp->id, 'name' => $info['name'], 'type' => $info['type'], 'extension' => $info['extension'], 'thumbs' => str_replace('_', '', $config['thumbSuffix']), 'size' => $info['size'], 'base_url' => $config['basePath'] . $info['savename'], 'status' => 0, 'createtime' => time());
$info['fileid'] = $this->add($data);
return array('status' => 0, 'msg' => '上传成功!', 'data' => $info);
}
}
示例3: editor_up
public function editor_up()
{
//$savePath 为项目下的上传目录名 如 uploads 会是 上传到__ROOR__/uploads下,为空则上传到__ROOT__/uploads/thinkeditor下
// $saveRule为上传文件命名规则,例如可以是 time uniqid com_create_guid 等,例如可以是 time uniqid com_create_guid 等 默认为time参考tp的上传类
// 例如可以是 time uniqid com_create_guid 等
$savePath = 'uploads';
$saveRule = 'time';
import("@.ORG.UploadFile");
$savePath = $savePath ? './' . $savePath : './Uploads/thinkeditor';
$savePath = substr($savePath, -1) != '/' ? $savePath . '/' : $savePath;
$maxSize = $_POST['temaxsize'] ? $_POST['temaxsize'] : -1;
$upload = new UploadFile($maxSize, '', '', $savePath, $saveRule);
//传给js的参数 $savepath是上传的文件的生成路径,$isupload是上传是否成功的布尔值
$savepath = '';
$isupload = 'false';
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
$info = $upload->uploadOne($_FILES['teupload']);
if ($info) {
$isupload = 'true';
$savepath = $upload->savePath . $info[0]['savename'];
$savepath = substr($savepath, 1);
} else {
$error = $upload->getErrorMsg();
}
}
import('@.TagLib.TagLibTp');
//上面的上传只是写个例子,用户上传可以自定义的,但是下面的是传给编辑器的
//参数必须为$isupload,是否成功,上传后的文件相对路径$savepath必须相对于项目根目录的,错误信息
TagLibTp::think_upload($isupload, $savepath, $error);
}
示例4: upload_file
/**
* 上传文件
* @param Array $file $_FILES['pic'] 上传的数组
* @param String $type 上传文件类型 pic为图片
* @return Array 上传成功返回文件保存信息,失败返回错误信息
*/
protected function upload_file($file, $dir, $size = 3145728, $type = array('jpg', 'gif', 'png', 'jpeg'))
{
import('@.ORG.Util.UploadFile');
//引入上传类
$upload = new UploadFile();
$upload->maxSize = $size;
// 设置附件上传大小
$upload->allowExts = $type;
// 上传文件的(后缀)(留空为不限制),,
//上传保存
$upload->savePath = $dir;
// 设置附件上传目录
$upload->autoSub = true;
// 是否使用子目录保存上传文件
$upload->subType = 'date';
// 子目录创建方式,默认为hash,可以设置为hash或者date日期格式的文件夹名
$upload->saveRule = 'uniqid';
// 上传文件的保存规则,必须是一个无需任何参数的函数名
//执行上传
$execute = $upload->uploadOne($file);
//执行上传操作
if (!$execute) {
// 上传错误提示错误信息
return array('status' => false, 'info' => $upload->getErrorMsg());
} else {
//上传成功 获取上传文件信息
return array('status' => true, 'info' => $execute);
}
}
示例5: upload
/**
* 单个文件上传
*
* @param [type] $fileFields [description]
* @return [type] [description]
*/
public static function upload($fileFields, $params = false)
{
$conf = Config::get('', 'base');
$params['thumbSize'] = array(400, 400);
Yii::import('application.vendors.*');
require_once 'Tp/UploadFile.class.php';
$upload = new UploadFile();
// 设置上传文件大小
$maxSize = isset($params['maxSize']) ? $params['maxSize'] : $conf['upload_max_size'];
$upload->maxSize = $maxSize * 1024;
// 设置上传文件类型
$upload->allowExts = isset($params['allowExts']) ? explode(',', $params['allowExts']) : explode(',', $conf['upload_allow_ext']);
// 设置附件上传目录
$upload->savePath = self::_saveRule($params['saveRule']);
// 设置需要生成缩略图,仅对图像文件有效
$upload->thumb = isset($params['thumb']) ? $params['thumb'] : $conf['thumb'];
// 设置需要生成缩略图的文件后缀
$upload->thumbPrefix = 'thumb_';
// 生产2张缩略图
// 设置缩略图最大宽度
$upload->thumbMaxWidth = $params['thumbSize'][0];
// 设置缩略图最大高度
$upload->thumbMaxHeight = $params['thumbSize'][1];
// 设置上传文件规则
$upload->saveRule = md5(time() . mt_rand(5, 15));
// 删除原图
$upload->thumbRemoveOrigin = false;
$file = $upload->uploadOne($fileFields);
if (!is_array($file)) {
return $upload->getErrorMsg();
} else {
// 重新整理返回数据
$fileget['name'] = $file[0]['name'];
$fileget['type'] = $file[0]['type'];
$fileget['size'] = $file[0]['size'];
$fileget['extension'] = $file[0]['extension'];
$fileget['savepath'] = $file[0]['savepath'];
$fileget['savename'] = $file[0]['savename'];
$fileget['hash'] = $file[0]['hash'];
$fileget['pathname'] = $upload->savePath . $file[0]['savename'];
if ($conf['upload_water_status'] == 'open') {
require_once 'Tp/Image.class.php';
Image::water($fileget['pathname'], './' . $conf['upload_water_file'], null, $conf['upload_water_trans']);
}
// 缩略图返回
if (true == $upload->thumb) {
$fileget['thumb'] = $upload->thumbPrefix . $file[0]['savename'];
$fileget['paththumbname'] = $upload->savePath . $upload->thumbPrefix . $file[0]['savename'];
}
return $fileget;
}
}
示例6: upload
/**
* 单个文件上传
*
* @param [type] $fileFields [description]
* @return [type] [description]
*/
public static function upload($fileFields, $params = array('thumb' => false, 'thumbSize' => array(400, 400), 'allowExts' => 'jpg,gif,png,jpeg', 'maxSize' => 3292200))
{
Yii::import('application.vendor.*');
require_once 'Tp/UploadFile.class.php';
$upload = new UploadFile();
// 设置上传文件大小
$upload->maxSize = isset($params['maxSize']) ? $params['maxSize'] : Config::get('maxSize');
// 设置上传文件类型
$upload->allowExts = isset($params['allowExts']) ? explode(',', $params['allowExts']) : explode(',', Config::get('upload_allow_ext'));
// 设置附件上传目录
empty($params['saveRule']) && ($params['saveRule'] = array('rule' => 'default', 'format' => 'Ymd', 'path' => 'uploads/'));
$upload->savePath = self::_saveRule($params['saveRule']);
if ($params['thumb']) {
// 设置需要生成缩略图,仅对图像文件有效
$upload->thumb = isset($params['thumb']) ? $params['thumb'] : Config::get('thumb');
// 设置需要生成缩略图的文件后缀
$upload->thumbPrefix = 'thumb_';
// 生产2张缩略图
// 设置缩略图最大宽度
$upload->thumbMaxWidth = $params['thumbSize'][0];
// 设置缩略图最大高度
$upload->thumbMaxHeight = $params['thumbSize'][1];
}
// 设置上传文件规则
$upload->saveRule = 'uniqid';
// 删除原图
$upload->thumbRemoveOrigin = false;
$file = $upload->uploadOne($fileFields);
if (!is_array($file)) {
return $upload->getErrorMsg();
} else {
// 重新整理返回数据
$fileget['name'] = $file[0]['name'];
$fileget['type'] = $file[0]['type'];
$fileget['size'] = $file[0]['size'];
$fileget['extension'] = $file[0]['extension'];
$fileget['savepath'] = $file[0]['savepath'];
$fileget['savename'] = $file[0]['savename'];
$fileget['hash'] = $file[0]['hash'];
$fileget['pathname'] = $upload->savePath . $file[0]['savename'];
if (Config::get('upload_water_status') == 'open') {
require_once 'Tp/Image.class.php';
Image::water($fileget['pathname'], './' . Config::get('upload_water_file'), null, Config::get('upload_water_trans'));
}
// 缩略图返回
if (true == $upload->thumb) {
$fileget['thumb'] = $upload->thumbPrefix . $file[0]['savename'];
$fileget['paththumbname'] = $upload->savePath . $upload->thumbPrefix . $file[0]['savename'];
}
return $fileget;
}
}
示例7: import
function upload_pic($file, $type, $thumb = true, $water = false, $thumbPrefix = 'm_,s_', $thumbMaxWidth = '757,77', $thumbMaxHeight = '426,58')
{
import("ORG.Net.UploadFile");
$upload = new UploadFile();
// $uploadList = array();
// foreach($pics as $key=>$file)
// {
if (!empty($file['name'])) {
//设置上传文件大小
$upload->maxSize = 2 * 1024 * 1024;
//设置上传文件类型
$upload->allowExts = explode(',', $type);
$save_dir = "Uploads/pic/loginImg/" . date('Y') . '/' . date('Ymd');
//创建文件夹
@$this->create_dir($save_dir);
//设置附件上传目录
$upload->savePath = $save_dir . '/';
//设置上传文件规则
$upload->saveRule = uniqid;
//设置需要生成缩略图,仅对图像文件有效
$upload->thumb = $thumb;
// 设置引用图片类库包路径
$upload->imageClassPath = 'ORG.Util.Image';
//设置需要生成缩略图的文件后缀
$upload->thumbPrefix = $thumbPrefix;
//生产2张缩略图
//设置缩略图最大宽度
$upload->thumbMaxWidth = $thumbMaxWidth;
//$upload->thumbMaxWidth = '414,311';
//设置缩略图最大高度
$upload->thumbMaxHeight = $thumbMaxHeight;
//$upload->thumbMaxHeight = '414,311';
$upload->thumbRemoveOrigin = false;
//不删除原图
$info = $upload->uploadOne($file);
if ($info) {
//取得成功上传的文件信息
$uploadInfo = $info;
} else {
//捕获上传异常
$this->error($upload->getErrorMsg());
}
}
// }
//返回数据对象
return $uploadInfo;
}
示例8: xheditorUpImg
public function xheditorUpImg()
{
require_once CLASS_DIR . 'UploadFile.class.php';
$upload = new UploadFile();
$upload->maxSize = 1 * 1024 * 1024;
//1M 设置上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg', 'bmp');
//设置上传类型
$upload->savePath = 'upload/xheditor/' . date('Ym') . '/';
// 设置上传目录
$upload->saveRule = date("YmdHis");
//上传文件的保存规则
print_r($upload->getUploadFileInfo());
if (!$upload->uploadOne($_FILES['filedata'])) {
$error = $upload->getErrorMsg();
$statusCode = 300;
$message = '上传失败,请重新上传';
} else {
$message = '恭喜您,上传成功';
$statusCode = 200;
$uploadList = $upload->getUploadFileInfo();
$img = '/' . $upload->savePath . $uploadList[0]['savename'];
//返回上传的目录
}
$return = array();
if ($_REQUEST['type'] == 'uploadify') {
//需要在jquery.uploadify.js中配置上传的文件
$return['statusCode'] = $statusCode;
$return['message'] = $message;
$return['url'] = $img;
$return['navTabId'] = "";
$return['rel'] = "";
$return['callbackType'] = "";
$return['forwardUrl'] = "";
$return['confirmMsg'] = "";
} else {
$return['err'] = $error;
$return['msg'] = $img;
}
echo json_encode($return);
exit;
}
示例9: upload
public function upload()
{
//导入上传类
import('ORG.Net.UploadFile');
//初始化上传类并进行一些配置
$upload = new UploadFile();
$upload->maxSize = 3145728;
$upload->allowExts = array('xls', 'xlsx');
$upload->savePath = __ROOT__ . '/Public/upload/';
//上传文件并返回文件信息
$info = $upload->uploadOne($_FILES['excelData']);
//保存文件路径
$filename = $info[0]['savepath'] . $info[0]['savename'];
//保存文件扩展名
$extension = $info[0]['extension'];
//判断是否上传成功,若否,抛出对应错误
if (!$info) {
$this->error($upload->getErrorMsg());
} else {
$this->read_excel($filename, $extension);
}
}
示例10: _uploadone
private function _uploadone($imgage, $path = '', $isThumb = true)
{
import("ORG.Net.UploadFile");
$upload = new UploadFile();
//设置上传文件大小
$upload->maxSize = 3292200;
$upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
if (empty($path)) {
$upload->savePath = './data/items/';
} else {
$upload->savePath = $path;
}
if ($isThumb === true) {
$upload->thumb = true;
$upload->imageClassPath = 'ORG.Util.Image';
$upload->thumbPrefix = 'm_';
$upload->thumbMaxWidth = '450';
//设置缩略图最大高度
$upload->thumbMaxHeight = '450';
$upload->saveRule = uniqid;
$upload->thumbRemoveOrigin = true;
}
if (!$upload->uploadOne($imgage)) {
//捕获上传异常
$this->error($upload->getErrorMsg());
} else {
//取得成功上传的文件信息
$uploadList = $upload->getUploadFileInfo();
}
return $uploadList;
}
示例11: edituppic
public function edituppic()
{
import('ORG.Net.UploadFile');
$upload = new UploadFile();
// 实例化上传类
$upload->maxSize = 5242880;
// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');
// 设置附件上传类型
$upload->savePath = './uploads/pic/' . date('Ym') . '/';
// 设置附件上传目录
$upload->thumb = true;
$upload->thumbType = 0;
$upload->thumbPrefix = 'b_,s_';
$upload->thumbMaxWidth = '500,150';
$upload->thumbMaxHeight = '1000,150';
$upload->thumbRemoveOrigin = true;
$upload->saveRule = time() . '_' . mt_rand(1000000, 9999999);
$info = $upload->uploadOne($_FILES['imgFile']);
$file_url = '/uploads/pic/' . date('Ym') . '/b_' . $info['0']['savename'];
if ($info) {
$data['error'] = 0;
$data['url'] = $file_url;
$this->ajaxReturn($data, 'JSON');
} else {
$this->ajaxReturn(0, $upload->getErrorMsg(), 0);
}
}
示例12: catch
}
$db = Db::getInstance();
try {
$db->connect();
} catch (Exception $e) {
echo getJsonResponse(1, '数据库连接错误', null);
Log::error_log("数据库连接错误");
exit;
}
if (!checkUserToken($db, $_POST['user_id'], $_POST['access_token'])) {
echo getJsonResponse(2, '用户token错误', null);
exit;
}
$config1 = array('maxSize' => 2100000, 'allowExts' => array('png', 'jpg'), 'allowTypes' => array('image/png', 'image/jpeg'), 'savePath' => '../images/users/');
$uf = new UploadFile($config1);
$res = $uf->uploadOne($_FILES['image']);
if ($res) {
$savePath = 'http://' . getServerIp() . '/images/users/' . $res['savename'];
if (false !== $db->execute("update users set imageurl='{$savePath}' where user_id={$_POST['user_id']};")) {
echo getJsonResponse(0, '上传成功', null);
} else {
echo getJsonResponse(1, $db->error, null);
}
$db->close();
} else {
if ($uf->errorNo == 1 || $uf->errorNo == 2 || $uf->errorNo == 8) {
echo getJsonResponse(3, $uf->errorMsg, null);
} else {
if ($uf->errorNo == 9) {
echo getJsonResponse(4, $uf->errorMsg, null);
} else {
示例13: import
function upload_pic($file, $type, $path, $thumb = false, $water = false, $thumbPrefix = 's_', $thumbMaxWidth = '125', $thumbMaxHeight = '125')
{
import("ORG.Net.UploadFile");
$upload = new UploadFile();
if (!empty($file['name'])) {
//设置上传文件大小
$upload->maxSize = 1 * 1024 * 1024;
//设置上传文件类型
$upload->allowExts = explode(',', $type);
$save_dir = $path . date('Y') . '/' . date('Ymd');
//创建文件夹
@$this->create_dir($save_dir);
//设置附件上传目录
$upload->savePath = $save_dir . '/';
//设置上传文件规则
$upload->saveRule = uniqid;
$info = $upload->uploadOne($file);
if ($info) {
//取得成功上传的文件信息
$uploadInfo = $info;
} else {
//捕获上传异常
$this->error($upload->getErrorMsg());
}
}
//返回数据对象
return $uploadInfo;
}
示例14: _upload
private function _upload($imgage, $path = '', $isThumb = false)
{
import("ORG.Net.UploadFile");
$upload = new UploadFile();
//设置上传文件大小
$upload->maxSize = 3292200;
$upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
$upload->saveRule = uniqid;
if (empty($savePath)) {
$upload->savePath = ROOT_PATH . '/data/items_cate/';
} else {
$upload->savePath = $path;
}
if (!$upload->uploadOne($imgage)) {
//捕获上传异常
$this->error($upload->getErrorMsg());
} else {
//取得成功上传的文件信息
$uploadList = $upload->getUploadFileInfo();
}
return $uploadList;
}
示例15: ajaxupimg2
public function ajaxupimg2()
{
// if($this->uid!=$_POST['uid'])
// {
// ajaxmsg('数据有误!',0);
// }
if (!empty($_FILES['imgfile2']['name'])) {
import('ORG.Net.UploadFile');
$upload = new UploadFile();
// 实例化上传类
$upload->maxSize = 3145728;
// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');
// 设置附件上传类型
$upload->savePath = './UF/Uploads/Idcard/';
// 设置附件上传目录
chmod($upload->savePath, 0777);
$upload->saveRule = date("YmdHis", time()) . rand(0, 1000) . "_{$this->uid}";
foreach ($_FILES as $key => $file) {
if (!empty($file['name'])) {
$upload->autoSub = true;
$upload->subType = 'date';
$info = $upload->uploadOne($file);
if ($info) {
// 保存附件信息
M('Photo')->add($info);
} else {
// 上传错误
ajaxmsg($upload->getErrorMsg(), 0);
}
}
}
//$info = $this->CUpload();
$img = $info[0]['savepath'] . $info[0]['savename'];
//$img[1] = $info[1]['savepath'].$info[1]['savename'];
}
if ($img) {
$c = M('member_info')->where("uid = {$this->uid}")->count('uid');
if ($c == 1) {
//$newid = M("member_info")->where("uid={$this->uid}")->setField('card_img',$img[0]);
//$newid = M("member_info")->where("uid={$this->uid}")->setField('card_back_img',$img[1]);
$newid = M("member_info")->where("uid={$this->uid}")->setField('card_back_img', $img);
} else {
$data['uid'] = $this->uid;
//$data['card_img'] = $img[0];
$data['card_back_img'] = $img;
$newid = M('member_info')->add($data);
}
session("idcardimg2", "1");
ajaxmsg('上传成功', 1);
} else {
ajaxmsg('上传失败,请重试', 0);
}
}