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); }
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'); }
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; }
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; } }
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; }
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 ''; }
function upload() { include_once "classes/Uploader.class.php"; //image-data is the name attribute used in <input type='file' /> $uploader = new Uploader("image-data"); $uploader->saveIn("img"); $fileUploaded = $uploader->save(); if ($fileUploaded) { $out = "new file uploaded"; } else { $out = "something went wrong"; } return $out; }
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; }
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; }
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); }
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; }
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']); }
<?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;
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; } }
/** * 上传广告图片 * @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; }
/** * 编辑文章 * * @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, // 'fileds'=》 // // )); $this->show_message('edit_article_successed', 'back_list', 'index.php?app=story', 'edit_again', 'index.php?app=story&act=edit&id=' . $article_id); } }
/** * 上传默认商品图片、默认店铺标志、默认会员头像 * * @author Hyber * @param array $images * @return array */ function _upload_images($images) { import('uploader.lib'); $image_urls = array(); foreach ($images as $image) { $file = $_FILES[$image]; if ($file['error'] != UPLOAD_ERR_OK) { continue; } $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->addFile($file); if ($uploader->file_info() === false) { continue; } $uploader->root_dir(ROOT_PATH); $image_urls[$image] = $uploader->save(UPLOAD_DIR, $image); } return $image_urls; }
//save and set default rename name $fileName = $_FILES['image-data']['name']; //TODO: use AJAX to check duplicate photo to avoid overwritting /* //same file name check and resolve if(file_exists("img/$fileName")){ //same file name exists, ask user to rename the upload file $renameForm = include "views/admin/file-rename-html.php"; return $renameForm; }*/ //create Uploader $uploader = new Uploader('image-data'); //choose where to save $uploader->saveIn("img"); try { //check file upload exception include_once "models/FileUploadException.class.php"; if ($_FILES['image-data']['error'] === UPLOAD_ERR_OK) { //no file upload err $uploader->save($fileName); $uploadOutput = "file should have been uploaded"; } else { throw new FileUploadException($_FILES['image-data']['error']); } } catch (Exception $e) { $uploadOutput = $e->getMessage(); } return $uploadOutput; } $imageManagerHTML = (include_once "views/admin/images-html.php"); return $imageManagerHTML;
/** * 处理上传标志 * * @author Hyber * @param int $brand_id * @return string */ function _upload_logo($brand_id) { $file = $_FILES['logo']; if ($file['error'] == UPLOAD_ERR_NO_FILE) { return ''; } import('uploader.lib'); //导入上传类 $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); //限制文件类型 $uploader->addFile($_FILES['logo']); //上传logo if (!$uploader->file_info()) { $this->show_warning($uploader->get_error(), 'go_back', 'index.php?app=brand&act=edit&id=' . $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; } }
function _upload_goods($store_id, $goods_id, $id) { import('uploader.lib'); $data = array(); /* store_logo */ $file = $_FILES[$id]; if ($file['error'] == UPLOAD_ERR_OK && $file != '') { $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->allowed_size(SIZE_STORE_LOGO); // 20KB $uploader->addFile($file); if ($uploader->file_info() === false) { $this->show_warning($uploader->get_error()); return false; } $uploader->root_dir(ROOT_PATH); $data['index_goods'] = $uploader->save('data/files/store_' . $store_id . '/goods_' . $goods_id, 'index_goods'); return $data['index_goods']; } }
/** * 处理上传标志 * * @author Garbin * @param int $partner_id * @return string */ function _upload_logo($partner_id) { import('uploader.lib'); //导入上传类 $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); //限制文件类型 $uploader->allowed_size(SIZE_STORE_PARTNER); // 100KB $uploader->addFile($_FILES['logo']); //上传logo /* 指定保存位置的根目录 */ $uploader->root_dir(ROOT_PATH); /* 上传 */ if ($file_path = $uploader->save('data/files/store_' . $this->_store_id . '/partner', $partner_id)) { return $file_path; } else { return false; } }
function uploadedfile() { import('image.func'); import('uploader.lib'); $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->allowed_size(SIZE_GOODS_IMAGE); // 2M $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']); $file['tmp_name'] = str_replace("\\\\", "\\", $file['tmp_name']); /* 推荐图片,判断图片尺寸是否符合要求 */ if ($this->instance == 'recommend_image') { $size = getimagesize($file['tmp_name']); $width = $size[0]; $height = $size[1]; if ($width != 1080 || $height != 540) { $res = Lang::get('must_size'); $this->view_iframe(); echo "<script type='text/javascript'>alert('{$res}');</script>"; return false; } /* 取到商品关联的图片 */ $uploadedfiles = $this->uploaded_files_mod->find(array('fields' => "f.*,goods_image.*", 'conditions' => "store_id=" . $this->store_id . " AND belong=" . BELONG_GOODS . " AND item_id=" . $this->id, 'join' => 'belongs_to_goodsimage', 'order' => 'add_time ASC')); foreach ($uploadedfiles as $key => $uploadedfile) { if ($uploadedfile['instance'] == 'recommend_image') { //删除原图片文件 @unlink($uploadedfile['file_path']); //删除原图片库存记录 $this->uploaded_files_mod->drop($uploadedfile['file_id']); } } } $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_GOODS) { $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/goods_' . time() % 200; } elseif ($this->belong == BELONG_STORE) { $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/other'; } elseif ($this->belong == BELONG_ARTICLE) { $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/article'; } $filename = $uploader->random_filename(); $file_path = $uploader->save($dirname, $filename); /* 处理文件入库 */ $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->id, 'add_time' => gmtime(), 'instance' => $this->instance); $file_id = $this->uploaded_files_mod->add($data); if (!$file_id) { $this->_error($uf_mod->get_error()); return false; } 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的缩略图 /* 更新商品相册 */ $mod_goods_image =& m('goodsimage'); $goods_image = array('goods_id' => $this->id, 'image_url' => $file_path, 'thumbnail' => $thumbnail, 'bignail' => $bignail, 'middlenail' => $middlenail, 'smallnail' => $smallnail, 'sort_order' => 255, 'file_id' => $file_id); if (!$mod_goods_image->add($goods_image)) { $this->_error($this->mod_goods_imaged->get_error()); return false; } $data['thumbnail'] = $thumbnail; } $data['instance'] = $this->instance; $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; } }
/** * 处理上传标志 * * @author psmoban.com * @param int $coupon_id * @return string */ function _upload_image($coupon_id) { $file = $_FILES['coupon_image']; if ($file['error'] == UPLOAD_ERR_NO_FILE) { return ''; } import('uploader.lib'); //导入上传类 $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); //限制文件类型 $uploader->addFile($_FILES['coupon_image']); //上传image if (!$uploader->file_info()) { $this->show_warning($uploader->get_error()); return false; } /* 指定保存位置的根目录 */ $uploader->root_dir(ROOT_PATH); /* 上传 */ if ($file_path = $uploader->save('data/files/mall/coupon', $coupon_id)) { return $file_path; } else { return false; } }
/** * 上传文件 * */ function _upload_files() { import('uploader.lib'); $data = array(); /* store_logo */ $file = $_FILES['store_logo']; if ($file['error'] == UPLOAD_ERR_OK && $file != '') { $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); //$uploader->allowed_size(SIZE_STORE_LOGO); // 20KB $uploader->addFile($file); if ($uploader->file_info() === false) { $this->show_warning($uploader->get_error()); exit; } $uploader->root_dir(ROOT_PATH); $data['store_logo'] = $uploader->save('data/files/store_' . $this->_store_id . '/other', 'store_logo'); } /* store_banner */ $file = $_FILES['store_banner']; if ($file['error'] == UPLOAD_ERR_OK && $file != '') { $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->allowed_size(SIZE_STORE_BANNER); // 200KB $uploader->addFile($file); if ($uploader->file_info() === false) { $this->show_warning($uploader->get_error()); return false; } $uploader->root_dir(ROOT_PATH); $data['store_banner'] = $uploader->save('data/files/store_' . $this->_store_id . '/other', 'store_banner'); } return $data; }
protected function _uploader($dir_id, $dir = null, $name = null, $uid) { //实例化 $upload = new Uploader($_FILES, $dir, $name); //设置上传目录 $type_id = $upload->getTypeId(); $dir = $uid . '/' . $type_id . '/' . $dir_id . '/'; $upload->setDir($dir); if ($upload->save()) { return self::_publicUpload2($upload, $dir_id, $uid); } else { Log::write(json_encode($upload->getError()), "ERR", 3, "uploader"); return false; } }
function edit() { $id = empty($_GET['id']) ? 0 : intval($_GET['id']); if (!IS_POST) { /* 是否存在 */ $gcategory = $this->_gcategory_mod->get_info($id); if (!$gcategory) { $this->show_warning('gcategory_empty'); return; } $this->assign('gcategory', $gcategory); /* 导入jQuery的表单验证插件 */ $this->import_resource(array('script' => 'jquery.plugins/jquery.validate.js')); $this->assign('parents', $this->_get_options($id)); $this->display('gcategory.form.html'); } else { if ($_FILES['rec_img']['name']) { import('uploader.lib'); $data = array(); $file = $_FILES['rec_img']; if ($file['error'] == UPLOAD_ERR_OK && $file != '') { $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->allowed_size(SIZE_STORE_LOGO); // 20KB $uploader->addFile($file); if ($uploader->file_info() === false) { $this->show_warning($uploader->get_error()); return false; } $uploader->root_dir(ROOT_PATH); $rec_img = $uploader->save('data/files/gcategory_' . $id, 'rec_img'); } } else { $rec_img = $_POST['rec_imgs']; } $data = array('cate_name' => $_POST['cate_name'], 'parent_id' => $_POST['parent_id'], 'sort_order' => $_POST['sort_order'], 'if_show' => $_POST['if_show'], 'rec_img' => $rec_img); /* 检查名称是否已存在 */ if (!$this->_gcategory_mod->unique(trim($data['cate_name']), $data['parent_id'], $id)) { $this->show_warning('name_exist'); return; } /* 检查级数 */ $depth = $this->_gcategory_mod->get_depth($id); $ancestor = $this->_gcategory_mod->get_ancestor($data['parent_id']); if ($depth + count($ancestor) > MAX_LAYER) { $this->show_warning('max_layer_error'); return; } /* 保存 */ $old_data = $this->_gcategory_mod->get_info($id); // 保存前的数据 $rows = $this->_gcategory_mod->edit($id, $data); if ($this->_gcategory_mod->has_error()) { $this->show_warning($this->_gcategory_mod->get_error()); return; } /* 如果改变了上级分类,更新商品表中相应记录的cate_id_1到cate_id_4 */ if ($old_data['parent_id'] != $data['parent_id']) { // 执行时间可能比较长,所以不限制了 _at(set_time_limit, 0); // 清除商城商品分类缓存 $cache_server =& cache_server(); $cache_server->delete('goods_category_0'); // 取得当前分类的所有子孙分类(包括自身) $cids = $this->_gcategory_mod->get_descendant_ids($id, true); // 找出这些分类中有商品的分类 $mod_goods =& m('goods'); $mod_gcate =& $this->_gcategory_mod; $sql = "SELECT DISTINCT cate_id FROM {$mod_goods->table} WHERE cate_id " . db_create_in($cids); $cate_ids = $mod_goods->getCol($sql); // 循环更新每个分类的cate_id_1到cate_id_4 foreach ($cate_ids as $cate_id) { $cate_id_n = array(0, 0, 0, 0); $ancestor = $mod_gcate->get_ancestor($cate_id, true); for ($i = 0; $i < 4; $i++) { isset($ancestor[$i]) && ($cate_id_n[$i] = $ancestor[$i]['cate_id']); } $sql = "UPDATE {$mod_goods->table} " . "SET cate_id_1 = '{$cate_id_n[0]}', cate_id_2 = '{$cate_id_n[1]}', cate_id_3 = '{$cate_id_n[2]}', cate_id_4 = '{$cate_id_n[3]}' " . "WHERE cate_id = '{$cate_id}'"; $mod_goods->db->query($sql); } } $this->show_message('edit_ok', 'back_list', 'index.php?app=gcategory', 'edit_again', 'index.php?app=gcategory&act=edit&id=' . $id); } }
function uploadedfile() { import('image.func'); import('uploader.lib'); $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->allowed_size(SIZE_GOODS_IMAGE); // 2M $upload_mod =& m('uploadedfile'); /* 取得剩余空间(单位:字节),false表示不限制 */ $store_mod =& m('store'); $settings = $store_mod->get_settings($this->store_id); $remain = $settings['space_limit'] > 0 ? $settings['space_limit'] * 1024 * 1024 - $upload_mod->get_file_size($this->store_id) : false; $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; } /* 判断能否上传 */ if ($remain !== false) { if ($remain < $file['size']) { $res = Lang::get('space_limit_arrived'); $this->view_iframe(); echo "<script type='text/javascript'>alert('{$res}');</script>"; return false; } } $uploader->root_dir(ROOT_PATH); $dirname = ''; if ($this->belong == BELONG_GOODS) { $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/goods_' . time() % 200; } elseif ($this->belong == BELONG_STORE) { $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/other'; } elseif ($this->belong == BELONG_ARTICLE) { $dirname = 'data/files/mall/store_' . $this->visitor->get('manage_store') . '/article'; } $filename = $uploader->random_filename(); $file_path = $uploader->save($dirname, $filename); /* 处理文件入库 */ $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->id, 'add_time' => gmtime()); $file_id = $upload_mod->add($data); if (!$file_id) { $this->_error($uf_mod->get_error()); return false; } if ($this->instance == 'goods_image') { /* 生成缩略图 */ $thumbnail = dirname($file_path) . '/small_' . basename($file_path); make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $thumbnail, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY); /* 更新商品相册 */ $mod_goods_image =& m('goodsimage'); $goods_image = array('goods_id' => $this->id, 'image_url' => $file_path, 'thumbnail' => $thumbnail, 'sort_order' => 255, 'file_id' => $file_id); if (!$mod_goods_image->add($goods_image)) { $this->_error($this->mod_goods_imaged->get_error()); return false; } $data['thumbnail'] = $thumbnail; } $data['instance'] = $this->instance; $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; } }
/** * 上传商品图片 * * @param int $goods_id * @return bool */ function _upload_image($goods_id) { import('image.func'); import('uploader.lib'); $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->allowed_size(SIZE_GOODS_IMAGE); // 400KB /* 取得剩余空间(单位:字节),false表示不限制 */ $store_mod =& m('store'); $settings = $store_mod->get_settings($this->_store_id); $upload_mod =& m('uploadedfile'); $remain = $settings['space_limit'] > 0 ? $settings['space_limit'] * 1024 * 1024 - $upload_mod->get_file_size($this->_store_id) : false; $files = $_FILES['new_file']; foreach ($files['error'] as $key => $error) { if ($error == UPLOAD_ERR_OK) { /* 处理文件上传 */ $file = array('name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'size' => $files['size'][$key], 'error' => $files['error'][$key]); $uploader->addFile($file); if (!$uploader->file_info()) { $this->_error($uploader->get_error()); return false; } /* 判断能否上传 */ if ($remain !== false) { if ($remain < $file['size']) { $this->_error('space_limit_arrived'); return false; } else { $remain -= $file['size']; } } $uploader->root_dir(ROOT_PATH); $dirname = 'data/files/store_' . $this->_store_id . '/goods_' . time() % 200; $filename = $uploader->random_filename(); $file_path = $uploader->save($dirname, $filename); $thumbnail = dirname($file_path) . '/small_' . basename($file_path); make_thumb(ROOT_PATH . '/' . $file_path, ROOT_PATH . '/' . $thumbnail, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY); /* 处理文件入库 */ $data = array('store_id' => $this->_store_id, 'file_type' => $file['type'], 'file_size' => $file['size'], 'file_name' => $file['name'], 'file_path' => $file_path, 'add_time' => gmtime()); $uf_mod =& m('uploadedfile'); $file_id = $uf_mod->add($data); if (!$file_id) { $this->_error($uf_mod->get_error()); return false; } /* 处理商品图片入库 */ $data = array('goods_id' => $goods_id, 'image_url' => $file_path, 'thumbnail' => $thumbnail, 'sort_order' => 255, 'file_id' => $file_id); if (!$this->_image_mod->add($data)) { $this->_error($this->_image_mod->get_error()); return false; } } } return true; }
/** * 上传头像 * * @param int $user_id * @return mix false表示上传失败,空串表示没有上传,string表示上传文件地址 */ function _upload_portrait($user_id) { $file = $_FILES['portrait']; 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->show_warning($uploader->get_error(), 'go_back', 'index.php?app=member&act=profile'); return false; } $uploader->root_dir(ROOT_PATH); return $uploader->save('data/files/mall/portrait/' . ceil($user_id / 500), $user_id); }
function _upload_image($store_id) { import('uploader.lib'); $uploader = new Uploader(); $uploader->allowed_type(IMAGE_FILE_TYPE); $uploader->allowed_size(SIZE_STORE_CERT); // 400KB $data = array(); for ($i = 1; $i <= 3; $i++) { $file = $_FILES['image_' . $i]; if ($file['error'] == UPLOAD_ERR_OK) { if (empty($file)) { continue; } $uploader->addFile($file); if (!$uploader->file_info()) { $this->_error($uploader->get_error()); return false; } $uploader->root_dir(ROOT_PATH); $dirname = 'data/files/mall/application'; $filename = 'store_' . $store_id . '_' . $i; $data['image_' . $i] = $uploader->save($dirname, $filename); } } return $data; }