本文整理汇总了PHP中Upload::upload方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::upload方法的具体用法?PHP Upload::upload怎么用?PHP Upload::upload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Upload
的用法示例。
在下文中一共展示了Upload::upload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hd_uploadify
/**
* Uploadify上传文件处理
*/
public function hd_uploadify()
{
$uploadModel = M('upload');
$size = Q('size') ? Q('size') : C('allow_size');
$upload = new Upload(Q('post.upload_dir'), array(), $size);
$file = $upload->upload();
if (!empty($file)) {
$file = $file[0];
$file['uid'] = session('uid');
//图片加水印
if ($file['image'] && Q('water')) {
$img = new Image();
$img->water($file['path']);
}
//写入upload表
$uploadModel->add($file);
$data = $file;
$data['status'] = 1;
$data['isimage'] = $file['image'] ? 1 : 0;
} else {
$data['status'] = 0;
$data['message'] = $upload->error;
}
echo json_encode($data);
exit;
}
示例2: addHander
public function addHander()
{
// p($_FILES);
// p($_POST);
preg_match_all('/<\\s*img\\s+[^>]*?src\\s*=\\s*(\'|\\")(.*?)\\">/i', $_POST['details'], $result, PREG_SET_ORDER);
$dir = MYPHP_TEMP_PATH . "/Article/" . $_POST['column_id'] . '/' . $_POST['category_id'];
is_dir($dir) || mkdir($dir, 0777, true);
chmod($dir, 0777);
$aid = (int) file_get_contents(MYPHP_TEMP_PATH . '/Dbid/Article/Article/dbid.txt');
$fileName = $dir . '/' . date('Y-m-d') . '-' . $_POST['column_id'] . '-' . $_POST['category_id'] . '-' . ($aid + 1) . '.txt';
$data = array();
foreach ($result as $v) {
$data[] = $v[0];
}
// p($fileName);die;
file_put_contents($fileName, serialize($data));
$details = preg_replace('/<\\s*img\\s+[^>]*?src\\s*=\\s*(\'|\\")(.*?)\\">/i', "<baseImg/>", $_POST['details']);
if (isset($_FILES['thumb'])) {
$upload = new Upload('Upload/Article/images/' . date("Y/m/d"));
$files = $upload->upload();
}
// p($files);
// die;
$articleData = array('column_id' => $_POST['column_id'], 'category_id' => $_POST['category_id'], 'title' => $_POST['title'], 'tags' => $_POST['tags'], 'recommend' => $_POST['recommend'], 'author' => isset($_POST['author']) ? $_POST['author'] : $_SESSION['uname'], 'source' => $_POST['source'], 'details' => $_POST['details'], 'display' => $_POST['display'], 'thumb' => empty($files[0]['path']) ? "" : $files[0]['path'], 'image' => $fileName, 'create_time' => time());
$articleData['details'] = $details;
if (K('Article')->addArticle($articleData)) {
$this->success('文章添加成功', __APP__ . '?c=Article&a=listArticle');
} else {
$this->error('文章添加失败');
}
}
示例3: addUser
public function addUser()
{
if (IS_POST) {
//上传头像的路径
$path = 'Upload/UserImages/' . date("Y/m/d");
$data = $_POST;
$data['password'] = md5($data['password']);
$data['create_time'] = time();
$user = K('User');
if (!$user->valid($data['username'])) {
if (isset($_FILES['user_img'])) {
$upload = new Upload($path);
$files = $upload->upload();
}
$data['user_img'] = $files[0]['path'];
if ($user->addUser($data)) {
$this->success('用户添加成功!', U('listUser', array('p' => 1)));
} else {
$this->error('用户添加失败了,请检查填写信息!', U('addUser'));
}
} else {
$this->error('用户添加失败,请检查填写信息!', U('addUser'));
}
}
$this->display();
}
示例4: profileActAction
public function profileActAction()
{
$m['realname'] = $this->getPost('realname');
$m['provinceID'] = $this->getPost('areaProvince');
$m['cityID'] = $this->getPost('areaCity');
$m['regionID'] = $this->getPost('areaRegion');
$m['province'] = $this->load('Province')->getProvinceNameByID($m['provinceID']);
$m['city'] = $this->load('City')->getCityNameByID($m['cityID']);
if ($m['regionID']) {
$m['region'] = $this->load('Region')->getRegionNameByID($m['regionID']);
}
$code = $this->m_user->UpdateByID($m, USER_ID);
// Upload avatar if selected
if ($_FILES['avatar']['name']) {
$fileName = CUR_TIMESTAMP;
$up = new Upload($_FILES['avatar'], UPLOAD_PATH . '/');
$result = $up->upload($fileName);
if ($result == 1) {
$m['avatar'] = $fileName . '.' . $up->extension;
$this->m_user->UpdateByID($m, USER_ID);
} else {
jsAlert($result);
}
}
if (FALSE === $code && $result != 1) {
jsAlert('编辑个人信息失败, 请重试');
}
$this->redirect('/user/profile/edit');
}
示例5: hd_uploadify
/**
* Uploadify上传文件处理
*/
public function hd_uploadify()
{
$uploadModel = M('upload');
//上传文件类型
if (isset($_POST['type'])) {
$type = str_replace('*.', '', $_POST['type']);
$type = explode(';', $type);
} else {
$type = array();
}
$size = Q('size') ? Q('size') : C('allow_size');
$upload = new Upload(Q('upload_dir'), $type, $size);
$file = $upload->upload();
if (!empty($file)) {
$file = $file[0];
$file['uid'] = $_SESSION['user']['uid'];
//图片加水印
if ($file['image'] && Q('water')) {
$img = new Image();
$img->water($file['path']);
}
//写入upload表
$uploadModel->add($file);
$data = $file;
$data['status'] = 1;
} else {
$data['status'] = 0;
$data['message'] = $upload->error;
}
echo json_encode($data);
exit;
}
示例6: hd_uploadify
/**
* Uploadify上传文件处理
*/
public function hd_uploadify()
{
$uploadModel = M('upload');
//开启裁切
C('UPLOAD_IMG_RESIZE_ON', true);
C('upload_img_max_width', $_POST['upload_img_max_width']);
C('upload_img_max_height', $_POST['upload_img_max_height']);
$upload = new Upload(Q('post.upload_dir'), array(), array(), Q("water", null, "intval"));
$file = $upload->upload();
if (!empty($file)) {
$file = $file[0];
$file['uid'] = session('uid');
$data['stat'] = 1;
$data['url'] = __ROOT__ . '/' . $file['path'];
$data['path'] = $file['path'];
$data['filename'] = $file['filename'];
$data['name'] = $file['name'];
$data['basename'] = $file['basename'];
$data['thumb'] = array();
$data['isimage'] = $file['image'];
//写入upload表
$uploadModel->add($file);
} else {
$data['stat'] = 0;
$data['msg'] = $upload->error;
}
echo json_encode($data);
exit;
}
示例7: upload
/**
* 文件上传
* @param array $files 要上传的文件列表(通常是$_FILES数组)
* @param array $setting 文件上传配置
* @param string $driver 上传驱动名称
* @param array $config 上传驱动配置
* @return array 文件上传成功后的信息
*/
public function upload($files, $setting, $driver = 'Local', $config = null)
{
$setting['callback'] = array($this, 'isFile');
$setting['removeTrash'] = array($this, 'removeTrash');
$Upload = new Upload($setting, $driver, $config);
$info = $Upload->upload($files);
if ($info) {
//文件上传成功,记录文件信息
foreach ($info as $key => &$value) {
/* 已经存在文件记录 */
if (isset($value['id']) && is_numeric($value['id'])) {
continue;
}
/* 记录文件信息 */
$value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
//在模板里的url路径
if ($this->create($value) && ($id = $this->add())) {
$value['id'] = $id;
}
// else {
// //TODO: 文件上传成功,但是记录文件信息失败,需记录日志
// unset($info[$key]);
// }
}
return $info;
//文件上传成功
} else {
$this->error = $Upload->getError();
return false;
}
}
示例8: testExtension
public function testExtension()
{
$this->instance->init();
$this->instance->serverHandler =& $this->serverHandler;
$this->serverHandler->expects($this->once())->method('name')->willReturn('tests/samsonos.png');
$upload = new Upload(array('xls', 'gif'), null, $this->instance);
$this->assertFalse($upload->upload());
}
示例9: upload
/**
* 图片上传类
*/
public function upload()
{
$upload = new Upload('./Uploads/Logo/');
$file = $upload->upload();
if (empty($file)) {
//相当于 echo json_code('上传失败');exit;
$this->ajax('上传失败');
} else {
$data = $file[0];
$this->ajax($data);
}
}
示例10: categoryImage
/**
* 上传栏目图片
*/
public function categoryImage()
{
$upload = new Upload('Upload/Category');
$file = $upload->upload();
if (empty($file)) {
$this->ajax('上传失败');
} else {
$data = $file[0];
$data['uid'] = $_SESSION['user']['uid'];
M('upload')->add($data);
$this->ajax($data);
}
}
示例11: edit
public function edit()
{
if (IS_POST) {
$upload = new Upload();
$path = $upload->upload('logo');
if ($path) {
$_POST['logo'] = __ROOT__ . '/' . $path[0]['path'];
}
if ($this->db->save()) {
$this->success('修改成功!', 'index');
}
} else {
$nid = Q('id', 0, 'intval');
$this->assign('field', $this->db->find($nid));
$this->display();
}
}
示例12: set_config
/**
* 设置友情链接配置
*/
public function set_config()
{
if ($this->create()) {
//设置Logo
if (!empty($_FILES['logo'])) {
$upload = new Upload('upload/link/');
if ($file = $upload->upload()) {
//新logo文件名
$new_logo = $file[0]['dir'] . 'logo' . '.' . $file[0]['ext'];
//改名
rename($file[0]['path'], $new_logo);
$this->data['logo'] = $new_logo;
}
}
return $this->where('id=1')->update();
}
}
示例13: edit_link
/**
* 修改链接
* @return mixed
*/
public function edit_link()
{
if ($this->create()) {
//设置Logo
if (!empty($_FILES['logo'])) {
$upload = new Upload('upload/link/');
if ($file = $upload->upload()) {
$this->data['logo'] = $file[0]['path'];
//删除原logo文件
$logo = $this->where('id=' . Q('id'))->getField('logo');
if (is_file($logo)) {
unlink($logo);
}
}
}
return $this->save();
}
}
示例14: addTemplate
public function addTemplate()
{
if (IS_POST) {
$data = $_POST;
$data['create_time'] = time();
$path = 'Upload/TemplateImages/';
if (isset($_FILES['thumb'])) {
$upload = new Upload($path);
$files = $upload->upload();
}
$data['thumb'] = $files[0]['path'];
if (K('Template')->addTemplate($data)) {
$this->success('模板风格添加成功添加成功!', U('template'));
} else {
$this->error('模板风格添加失败了,请检查填写信息!', U('addTemplate'));
}
// p($data);die;
}
$this->display();
}
示例15: edit_article
public function edit_article()
{
if ($this->create()) {
/**
* 修改内容图片
* 如果$_FILES['thumb']['name']为空,没上传图(还用旧的)
*/
//如果有上传的图片数据时才进行缩略图上传处理
if (!empty($_FILES['thumb']['name'])) {
//文章缩略图上传处理
$upload = new Upload('upload/article/' . date("Y/m/d"));
$file = $upload->upload();
$this->data['thumb'] = $file[0]['path'];
//删除旧的缩略图
$thumb = $this->where("id=" . Q("id"))->getField('thumb');
is_file($thumb) and unlink($thumb);
}
return $this->save();
}
}