Onex ecstore前台图片操作详解
Ecstore前台图片操作详解如下:
/*
*取图片
*$images_id 图片的 images_id
*$parmas ('l' 'm' 's')l是大图,m是中图,s是小图, 不使用则取原图
**/
$strorager = kernel::single("base_storager");
$image_src = $strorager->image_path($images_id,$parmas);
$this->pagedata['image_url'] = $images_url;
/*
*前台保存
*$images_id string 图片的 images_id
*$parmas array array('L' 'M' 'S')L是大图,M是中图,S是小图
*$type string ('l' 'm' 's')l是大图,m是中图,s是小图, 不使用则取原图
**/
$mdl_img = app::get('image')->model('image');
$image_name = $_FILES['file']['name'];
$image_id = $mdl_img->store($_FILES['file']['tmp_name'],null,null,$image_name);
$mdl_img->rebuild($image_id,$parmas);
$strorager = kernel::single("base_storager");
$image_src =$strorager->image_path($image_id, $type);
前台的图片上传
/*
*无刷新上传图片,返回信息
* */
public function ajax_callback($status='error',$msg,$url=''){
header('Content-Type:text/html; charset=utf-8');
echo '';exit;
}
/**
* 截取文件名不包含扩展名
* @param 文件全名,包括扩展名
* @return string 文件不包含扩展名的名字
*/
private function fileext($filename)
{
return substr(strrchr($filename, '.'), 1);
}
function save_mphoto(){
if ( $_FILES['file']['name'] == "" ){
$this->ajax_callback('error',app::get('b2c')->_("请选择要上传的图片……"));
}
if ( $_FILES['file']['size'] > 314572800 ){
$this->ajax_callback('error',app::get('b2c')->_("上传文件不能超过300M!"));
}
if ( $_FILES['file']['name'] != "" )
{
$type=array("png","jpg","gif","jpeg","rar","zip");
if(!in_array(strtolower($this->fileext($_FILES['file']['name'])), $type))
{
$text = implode(",", $type);
$this->ajax_callback('error',app::get('aftersales')->_("您只能上传以下类型文件: ") . $text . "
");
}
$mdl_img = app::get('image')->model('image');
$image_name = $_FILES['file']['name'];
$image_id = $mdl_img->store($_FILES['file']['tmp_name'],null,null,$image_name);
$mdl_img->rebuild($image_id,array('L','M','S'));
if (isset($_REQUEST['type'])) {
$type = $_REQUEST['type'];
} else{
$type = 's';
}
$image_src = base_storager::image_path($image_id, $type);
}
$sql="update sdb_b2c_members set mphoto= '".$image_id."' where member_id='{$_POST['member_id']}'";
if(kernel::database()->exec($sql)){
$url=$this->gen_url(array('app'=>'b2c', 'ctl'=>'site_member', 'act'=>'mphoto'));
$this->ajax_callback('success',app::get('b2c')->_("上传成功……"),$url);exit;
}else{
$this->ajax_callback('error',app::get('b2c')->_("上传失败…… "));exit;
}
前台的图片上传