本文整理汇总了PHP中Uploader::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Uploader::save方法的具体用法?PHP Uploader::save怎么用?PHP Uploader::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uploader
的用法示例。
在下文中一共展示了Uploader::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function _upload_file()
{
$ret_info = array();
// 返回到客户端的信息
$file = $_FILES['Filedata'];
if ($file['error'] == UPLOAD_ERR_NO_FILE) {
$this->json_error('no_upload_file');
exit;
}
import('uploader.lib');
// 导入上传类
import('image.func');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
// 限制文件类型
$uploader->allowed_size(SIZE_GOODS_IMAGE);
// 限制单个文件大小2M
$uploader->addFile($file);
if (!$uploader->file_info()) {
$this->json_error($uploader->get_error());
exit;
}
/* 取得剩余空间(单位:字节),false表示不限制 */
$store_mod =& m('store');
$settings = $store_mod->get_settings($this->store_id);
$remain = $settings['space_limit'] > 0 ? $settings['space_limit'] * 1024 * 1024 - $this->mod_uploadedfile->get_file_size($this->store_id) : false;
/* 判断能否上传 */
if ($remain !== false) {
if ($remain < $file['size']) {
$this->json_error('space_limit_arrived');
exit;
}
}
/* 指定保存位置的根目录 */
$uploader->root_dir(ROOT_PATH);
$filename = $uploader->random_filename();
/* 上传 */
$file_path = $uploader->save($this->save_path, $filename);
// 保存到指定目录
if (!$file_path) {
$this->json_error('file_save_error');
exit;
}
$file_type = $this->_return_mimetype($file_path);
/* 文件入库 */
$data = array('store_id' => $this->store_id, 'file_type' => $file_type, 'file_size' => $file['size'], 'file_name' => $file['name'], 'file_path' => $file_path, 'belong' => $this->belong, 'item_id' => $this->item_id, 'add_time' => gmtime());
$file_id = $this->mod_uploadedfile->add($data);
if (!$file_id) {
$this->json_error('file_add_error');
exit;
}
if ($this->instance == 'goods_image') {
/* 生成缩略图 */
$thumbnail = dirname($file_path) . '/small_' . basename($file_path);
$bignail = dirname($file_path) . '/big_' . basename($file_path);
$middlenail = dirname($file_path) . '/middle_' . basename($file_path);
$smallnail = dirname($file_path) . '/little_' . basename($file_path);
make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $bignail, 900, 900, THUMB_QUALITY);
//生成900*900的缩略图
make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $middlenail, 420, 420, THUMB_QUALITY);
//生成420*420的缩略图
make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $smallnail, 60, 60, THUMB_QUALITY);
//生成60*60的缩略图
make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $thumbnail, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY);
//生成170*170的缩略图
/* 更新商品相册 */
$data = array('goods_id' => $this->item_id, 'image_url' => $file_path, 'thumbnail' => $thumbnail, 'bignail' => $bignail, 'middlenail' => $middlenail, 'smallnail' => $smallnail, 'sort_order' => 255, 'file_id' => $file_id);
if (!$this->mod_goods_image->add($data)) {
$this->json_error($this->mod_goods_imaged->get_error());
return false;
}
$ret_info = array_merge($ret_info, array('thumbnail' => $thumbnail));
}
/* 返回客户端 */
$ret_info = array_merge($ret_info, array('file_id' => $file_id, 'file_path' => $file_path, 'instance' => $this->instance));
$this->json_result($ret_info);
}
示例2: upload
public function upload()
{
//检查登录
$this->_login();
//单文件
if (!$_FILES || $_FILES["file"]["error"] > 0) {
echo '图片不能为空!';
throw new Exception('exit');
}
//处理上传的图片
$dir = 'goods/';
$upload = new Uploader($_FILES, $dir);
//保存图片
if ($upload->save()) {
$data['goods_photo'] = $upload->getUrl();
//图片路径
}
$da = array();
$da = $this->_getPost();
$data_new = array_merge($data, $da);
AdminGoodsM::add($data_new);
//跳转到未出售商品列表
$url = url('admin', 'admingoods::unsale');
header('Location:' . $url);
throw new Exception('exit');
}
示例3: uploadfile
function uploadfile($para)
{
import('image.func');
import('uploader.lib');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->allowed_size(2097152);
// 2M
$files = $para;
//$_FILES['activity_banner'];
if ($files['error'] == UPLOAD_ERR_OK) {
/* 处理文件上传 */
$file = array('name' => $files['name'], 'type' => $files['type'], 'tmp_name' => $files['tmp_name'], 'size' => $files['size'], 'error' => $files['error']);
$uploader->addFile($file);
if (!$uploader->file_info()) {
$data = current($uploader->get_error());
$res = Lang::get($data['msg']);
$this->view_iframe();
echo "<script type='text/javascript'>alert('{$res}');</script>";
return false;
}
$uploader->root_dir(ROOT_PATH);
$dirname = 'data/files/mall/weixin';
$filename = $uploader->random_filename();
$file_path = $uploader->save($dirname, $filename);
}
return $file_path;
}
示例4: uploadedfile
function uploadedfile()
{
import('image.func');
import('uploader.lib');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->allowed_size(2097152);
// 2M
$upload_mod =& m('uploadedfile');
$files = $_FILES['file'];
if ($files['error'] == UPLOAD_ERR_OK) {
/* 处理文件上传 */
$file = array('name' => $files['name'], 'type' => $files['type'], 'tmp_name' => $files['tmp_name'], 'size' => $files['size'], 'error' => $files['error']);
$uploader->addFile($file);
if (!$uploader->file_info()) {
$data = current($uploader->get_error());
$res = Lang::get($data['msg']);
$this->view_iframe();
echo "<script type='text/javascript'>alert('{$res}');</script>";
return false;
}
$uploader->root_dir(ROOT_PATH);
$dirname = '';
if ($this->belong == BELONG_ARTICLE) {
$dirname = 'data/files/mall/article';
}
$filename = $uploader->random_filename();
$file_path = $uploader->save($dirname, $filename);
/* 处理文件入库 */
$data = array('store_id' => $this->visitor->get('manage_store'), 'file_type' => $file['type'], 'file_size' => $file['size'], 'file_name' => $file['name'], 'file_path' => $file_path, 'belong' => $this->belong, 'item_id' => $this->id, 'add_time' => gmtime());
$file_id = $upload_mod->add($data);
if (!$file_id) {
$this->_error($uf_mod->get_error());
return false;
}
$data['file_id'] = $file_id;
$res = "{";
foreach ($data as $key => $val) {
$res .= "\"{$key}\":\"{$val}\",";
}
$res = substr($res, 0, strrpos($res, ','));
$res .= '}';
$this->view_iframe();
echo "<script type='text/javascript'>window.parent.add_uploadedfile({$res});</script>";
} elseif ($files['error'] == UPLOAD_ERR_NO_FILE) {
$res = Lang::get('file_empty');
$this->view_iframe();
echo "<script type='text/javascript'>alert('{$res}');</script>";
return false;
} else {
$res = Lang::get('sys_error');
$this->view_iframe();
echo "<script type='text/javascript'>alert('{$res}');</script>";
return false;
}
}
示例5: upload
function upload()
{
include_once "classes/Uploader.class.php";
$uploader = new Uploader("image-data");
$uploader->saveIn("img");
$fileUploaded = $uploader->save();
if ($fileUploaded) {
$out = "new file uploaded";
} else {
$out = "something went wrong";
}
return $out;
}
示例6: import
function _upload_image()
{
import('uploader.lib');
$file = $_FILES['ad_image_file'];
if ($file['error'] == UPLOAD_ERR_OK) {
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->addFile($file);
$uploader->root_dir(ROOT_PATH);
return $uploader->save('data/files/mall/template', $uploader->random_filename());
}
return '';
}
示例7: upload
function upload()
{
include_once 'models/Uploader.php';
$uploader = new Uploader('image_data');
$uploader->saveIn('img');
$fileUploaded = $uploader->save();
if ($fileUploaded) {
$out = 'new file uploaded';
} else {
$out = 'something went wrong';
}
$out .= "<pre>";
$out .= print_r($_FILES, true);
$out .= "</pre>";
return $out;
}
示例8: import
function _upload_image()
{
import('uploader.lib');
$images = array();
for ($i = 0; $i <= 50; $i++) {
$file = $_FILES['ad' . $i . '_image_file'];
if ($file['error'] == UPLOAD_ERR_OK) {
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->addFile($file);
$uploader->root_dir(ROOT_PATH);
$images[$i] = $uploader->save('data/files/mall/template', $uploader->random_filename());
}
}
return $images;
}
示例9: array
function _upload_file()
{
$ret_info = array();
// 返回到客户端的信息
$file = $_FILES['Filedata'];
if ($file['error'] == UPLOAD_ERR_NO_FILE) {
$this->json_error('no_upload_file');
exit;
}
import('uploader.lib');
// 导入上传类
import('image.func');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
// 限制文件类型
$uploader->allowed_size(2048000);
// 限制单个文件大小2M
$uploader->addFile($_FILES['Filedata']);
if (!$uploader->file_info()) {
$this->json_error($uploader->get_error());
exit;
}
/* 指定保存位置的根目录 */
$uploader->root_dir(ROOT_PATH);
$filename = $uploader->random_filename();
/* 上传 */
$file_path = $uploader->save($this->save_path, $filename);
// 保存到指定目录
if (!$file_path) {
$this->json_error('file_save_error');
exit;
}
$file_type = $this->_return_mimetype($file_path);
/* 文件入库 */
$data = array('store_id' => 0, 'file_type' => $file_type, 'file_size' => $file['size'], 'file_name' => $file['name'], 'file_path' => $file_path, 'belong' => $this->belong, 'item_id' => $this->item_id, 'add_time' => gmtime());
$file_id = $this->mod_uploadedfile->add($data);
if (!$file_id) {
$this->json_error('file_add_error');
return false;
}
/* 返回客户端 */
$ret_info = array('file_id' => $file_id, 'file_path' => $file_path);
$this->json_result($ret_info);
}
示例10: import
function _upload_image($num)
{
import('uploader.lib');
$images = array();
for ($i = 0; $i < $this->_num; $i++) {
$file = array();
foreach ($_FILES['ad_image_file'] as $key => $value) {
$file[$key] = $value[$i];
}
if ($file['error'] == UPLOAD_ERR_OK) {
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->addFile($file);
$uploader->root_dir(ROOT_PATH);
$images[$i] = $uploader->save('data/files/mall/template', $uploader->random_filename());
}
}
return $images;
}
示例11: upload
public function upload($upload_file, $type, $size, $url)
{
$file = $_FILES[$upload_file];
// if ($file['error']!=0){
// return array('message'=>'请选择文件');
// }
$uploader = new Uploader();
if ($type) {
$uploader->allowed_type($type);
// 限制文件类型
}
if ($size) {
$uploader->allowed_size($size);
}
$uploader->addFile($file);
if ($uploader->_file['error']) {
return array('message' => $uploader->_file['error']);
}
$newName = $uploader->random_filename();
//$uploader->root_dir(dirname(Yii::app()->BasePath));
$uploader->root_dir(Yii::app()->params['uploadPath']);
$uploader->save($url, $newName);
return array('filePath' => dirname(Yii::app()->BasePath), 'file' => $url . $newName . '.' . $uploader->_file['extension']);
}
示例12: isset
<?php
include_once "models/Uploader.class.php";
$imageSubmitted = isset($_POST['new-image']);
if ($imageSubmitted) {
$uploader = new Uploader('image-data');
$uploader->saveIn("img");
try {
$uploader->save();
$uploadMessage = "file uploaded!";
} catch (Exception $exception) {
$uploadMessage = $exception->getMessage();
}
}
$deleteImage = isset($_GET['delete-image']);
if ($deleteImage) {
$whichImage = $_GET['delete-image'];
unlink($whichImage);
}
$imageManagerHTML = (include_once "views/admin/images_html.php");
return $imageManagerHTML;
示例13: import
function _upload_logo($brand_id)
{
$file = $_FILES['brand_logo'];
if ($file['error'] == UPLOAD_ERR_NO_FILE || !isset($_FILES['brand_logo'])) {
return '';
}
import('uploader.lib');
//导入上传类
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
//限制文件类型
$uploader->addFile($_FILES['brand_logo']);
//上传logo
if (!$uploader->file_info()) {
$this->pop_warning($uploader->get_error());
if (ACT == 'brand_apply') {
$m_brand =& m('brand');
$m_brand->drop($brand_id);
}
return false;
}
/* 指定保存位置的根目录 */
$uploader->root_dir(ROOT_PATH);
/* 上传 */
if ($file_path = $uploader->save('data/files/mall/brand', $brand_id)) {
return $file_path;
} else {
return false;
}
}
示例14: import
/**
* 上传广告图片
* @param 无
* @return bool 上传是否成功
*/
function _upload_ad_image()
{
import('uploader.lib');
$file = $_FILES['ad_img'];
//修复tmp_name路径
$file['tmp_name'] = str_replace("\\\\", "\\", $file['tmp_name']);
/* 上传图片 */
if ($file['error'] == UPLOAD_ERR_OK) {
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->addFile($file);
$uploader->root_dir(ROOT_PATH);
return $uploader->save('data/files/mall/ad_images', $uploader->random_filename());
}
return false;
}
示例15: edit
/**
* 编辑文章
*
* @author Hyber
* @return void
*/
function edit()
{
$article_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if (!$article_id) {
$this->show_warning('no_such_article');
return;
}
if (!IS_POST) {
/* 当前文章的附件 */
$files_belong_article = $this->_uploadedfile_mod->find(array('conditions' => 'store_id = 0 AND belong = ' . BELONG_ARTICLE . ' AND item_id=' . $article_id, 'fields' => 'this.file_id, this.file_name, this.file_path', 'order' => 'add_time DESC'));
$find_data = $this->_article_mod->find($article_id);
if (empty($find_data)) {
$this->show_warning('no_such_article');
return;
}
$article = current($find_data);
$article['link'] = $article['link'] ? $article['link'] : '';
$article['tag'] = implode(",", unserialize($article['tag']));
$this->assign("id", $article_id);
$this->assign("belong", BELONG_ARTICLE);
$this->import_resource(array('script' => 'jquery.plugins/jquery.validate.js,change_upload.js'));
$this->assign('parents', $this->_get_options());
$this->assign('files_belong_article', $files_belong_article);
$this->assign('article', $article);
$template_name = $this->_get_template_name();
$style_name = $this->_get_style_name();
$this->assign('build_editor', $this->_build_editor(array('name' => 'content', 'content_css' => SITE_URL . "/themes/mall/{$template_name}/styles/{$style_name}/css/ecmall.css")));
$this->assign('build_upload', $this->_build_upload(array('belong' => BELONG_ARTICLE, 'item_id' => $article_id)));
// 构建swfupload上传组件
$this->display('story.form.html');
} else {
$data = array();
$data['title'] = $_POST['title'];
if (!empty($_POST['cate_id'])) {
$data['cate_id'] = $_POST['cate_id'];
}
$tags = explode(",", $_POST['tag']);
$data['tag'] = serialize($tags);
$data['link'] = $_POST['link'] == 'http://' ? '' : $_POST['link'];
$data['if_show'] = $_POST['if_show'];
$data['sort_order'] = $_POST['sort_order'];
$data['content'] = $_POST['content'];
$data['gid'] = $_POST['gid'];
$user_id = $this->visitor->get('user_id');
if ($_FILES['thumb']['tmp_name']) {
$file = $_FILES['thumb'];
if ($file['error'] != UPLOAD_ERR_OK) {
return '';
}
import('uploader.lib');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->addFile($file);
if ($uploader->file_info() === false) {
$this->json_error("上传失败");
}
$uploader->root_dir(ROOT_PATH);
$data['thumb'] = $uploader->save('data/files/mall/store/' . ceil($user_id / 500), time());
}
$etag = $data['tag'];
$infos = $this->_article_mod->get(array("conditions" => "article_id=" . $article_id . " and tag='{$etag}'"));
//检查是否更改
if (empty($infos)) {
$this->_article_mod->unlinkRelation("tag_to", $article_id);
//没有的话直接先删除
foreach ($tags as $t) {
$tag_id = $this->tag->get("tag_name='{$t}'");
//有没有该tag
$tid = $tag_id["tagid"];
if ($tid) {
//该tag有没有绑定关联表
$tag_name = $this->tagmap->getRow("select * from ecm_tagmap where tagid=" . $tid);
var_dump($tag_name);
if ($tag_name) {
//没有绑定的话就删除
$this->tag->createRelation("be_tag", $tid, $article_id);
} else {
$this->tag->drop($tid);
$id = $this->tag->add(array("tag_name" => $t));
$this->tag->createRelation("be_tag", $id, $article_id);
}
} else {
$id = $this->tag->add(array("tag_name" => $t));
$this->tag->createRelation("be_tag", $id, $article_id);
}
}
}
$rows = $this->_article_mod->edit($article_id, $data);
if ($this->_article_mod->has_error()) {
$this->show_warning($this->_article_mod->get_error());
return;
}
// $tagids=$this->tagmap->find(array(
// 'conditions'=>'article_id='.$article_id,
//.........这里部分代码省略.........