頁面內(nèi)容顯示和js加載
創(chuàng)新互聯(lián)服務(wù)項目包括滎經(jīng)網(wǎng)站建設(shè)、滎經(jīng)網(wǎng)站制作、滎經(jīng)網(wǎng)頁制作以及滎經(jīng)網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,滎經(jīng)網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到滎經(jīng)省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
<td class="zhaoxiang" id="file_uploader_"><a href="javascript:void(0)" class="zhaox"></a></td>
<script language="javascript" src="__STATIC__/js/mobile/mobile.js"></script>
<script language="javascript" src="__STATIC__/js/plug_module/plug-in_module.js"></script>
<script >
var ATTACH_ACCESS_KEY = '<?php echo $attach_access_key; ?>';
$(document).ready(function () {
init_fileuploader('file_uploader', root + '?m=upload&a=attach_upload&attach_access_key='+ATTACH_ACCESS_KEY);
});
</script>
php代碼編寫
//檢測并上傳圖片
public function attach_upload()
{
$id = $_REQUEST['id'] ? $_REQUEST['id'] : "";
$attach_access_key = $_REQUEST['attach_access_key'] ? $_REQUEST['attach_access_key'] : "";
import("@.ORG.UploadPic");
$upload = new UploadPic();
$savepath = "data/upload/weixinpic/".date("Y-m-d")."/";
if(!file_exists($savepath)){
$this->createDir($savepath);
}
$upload->initialize(array(
'allowed_types' => 'jpg,jpeg,png,gif',
'upload_path' => $savepath,
'is_p_w_picpath' => FALSE,
'max_size' => 10240
));
if (isset($_REQUEST['qqfile']))
{
$upload->do_upload($_REQUEST['qqfile'], true);
}
else if (isset($_FILES['qqfile']))
{
$upload->do_upload('qqfile');
}
else
{
return false;
}
if ($upload->get_error())
{
switch ($upload->get_error())
{
default:
die("{'error':'錯誤代碼: " . $upload->get_error() . "'}");
break;
case 'upload_invalid_filetype':
die("{'error':'文件類型無效'}");
break;
case 'upload_invalid_filesize':
die("{'error':'文件尺寸過大, 最大允 許尺寸為 10240 KB'}");
break;
}
}
if (! $upload_data = $upload->data())
{
die("{'error':'上傳失敗, 請與管理員聯(lián)系'}");
}
if ($upload_data['is_p_w_picpath'] == 1)
{
$config['p_w_upload_thumbnail'] = array(
'min' => array(
"w" => 170,
"h" => 110
),
'square' => array(
"w" => 90,
"h" => 90
)
);
import("@.ORG.Images");
$p_w_picpath = new Images();
foreach($config['p_w_upload_thumbnail'] AS $key => $val)
{
$thumb_file[$key] = $upload_data['file_path'] . $val['w'] . 'x' . $val['h'] . '_' . basename($upload_data['full_path']);
$p_w_picpath->initialize(array(
'quality' => 90,
'source_p_w_picpath' => $upload_data['full_path'],
'new_p_w_picpath' => $thumb_file[$key],
'width' => $val['w'],
'height' => $val['h']
))->resize();
}
}
$ptem['ue_id'] = $ueid;
$add = array();
$add['file_name'] = $upload_data['orig_name'];
$add['access_key'] = $attach_access_key;
$add['add_time'] = time();
$ainfo = M('attach')->where($ptem)->find();
if(!empty($ainfo)){
$maxid = M('attach')->where($ptem)->max("que_sort");
$add['que_sort'] = $maxid + 1;
}else{
$add['que_sort'] = 0;
}
if(false == strpos($upload_data['full_path'],"http://")){
$filepath = "http://".$_SERVER['HTTP_HOST']."/".$savepath.basename($upload_data['full_path']);// 文件真實路徑
}else{
$filepath = $savepath.basename($upload_data['full_path']);
}
$add['file_location'] = basename($upload_data['full_path']);
$add['user_que_content'] = $filepath;
$attach_id = M("attach")->add($add);
unset($add);
$output = array(
'success' => true,
'delete_url' => '?m=upload&a=remove_attach&attach_id=' . base64_encode(encode_hash(array(
'attach_id' => $attach_id,
'access_key' => $attach_access_key
))),
'attach_id' => $attach_id,
'attach_tag' => 'attach'
);
//獲取內(nèi)容
$attachinfo = M("attach")->where("id = " . intval($attach_id))->find();
if (!empty($attachinfo))
{
$data = $this->parse_attach_data(array($attachinfo), 'square');
$attach_info = $data[intval($attach_id)];
}
if ($attach_info['thumb'])
{
$output['thumb'] = $attach_info['thumb'];
}
echo htmlspecialchars(json_encode($output), ENT_NOQUOTES);
}
//刪除圖片附件
public function remove_attach()
{
$attach_id = $_REQUEST['attach_id'] ? trim($_REQUEST['attach_id']) : '';
//判斷id是否為空
if(!$attach_id){
echo str_replace(array("\r", "\n", "\t"), '', json_encode(array('rsm' => "圖片id不存在無法刪除",'errno' => 0,'err' => "圖片id不存在無法刪除")));
exit;
}
if ($attach_info = decode_hash(base64_decode($attach_id)))
{
$id = $attach_info['attach_id'];
$access_key = $attach_info['access_key'];
//判斷圖片是否存在
if (! $attach = M("attach")->where("id = " . intval($id) . " AND access_key = '" . $access_key . "'")->find())
{
echo str_replace(array("\r", "\n", "\t"), '', json_encode(array('rsm' => "圖片id不存在無法刪除",'errno' => 0,'err' => "圖片id不存在無法刪除")));
exit;
}
//刪除圖片
M("attach")->where("id = " . intval($id) . " AND access_key = '" . $access_key . "'")->delete();
//刪除圖片文件
$attach_dir = "data/upload/weixinpic/".date("Y-m-d")."/";
$config['p_w_upload_thumbnail'] = array(
'min' => array(
"w" => 170,
"h" => 110
),
'square' => array(
"w" => 90,
"h" => 90
)
);
foreach($config['p_w_upload_thumbnail'] AS $key => $val)
{
@unlink($attach_dir . $val['w'] . 'x' . $val['h'] . '_' . $attach['file_location']);
}
@unlink($attach_dir . $attach['file_location']);
}
echo str_replace(array("\r", "\n", "\t"), '', json_encode(array('rsm' => null,'errno' => 1,'err' => null)));
exit;
}
//處理并解析附件數(shù)據(jù)
public function parse_attach_data($attach, $size = null)
{
if (!$attach)
{
return false;
}
$config['p_w_upload_thumbnail'] = array(
'min' => array(
"w" => 170,
"h" => 110
),
'square' => array(
"w" => 90,
"h" => 90
)
);
$attach_url = "data/upload/weixinpic/".date("Y-m-d")."/";
foreach ($attach as $key => $data)
{
$attach_list[$data['id']] = array(
'id' => $data['id'],
'is_p_w_picpath' => 1,
'file_name' => $data['file_name'],
'access_key' => $data['access_key'],
'p_w_upload' => $data['user_que_content'],
);
if ($size)
{
$attach_list[$data['id']]['thumb'] = $attach_url . '/' . $config['p_w_upload_thumbnail'][$size]['w'] . 'x' . $config['p_w_upload_thumbnail'][$size]['h'] . '_' . $data['file_location'];
}
}
return $attach_list;
}
4.效果圖
本文題目:php,js實現(xiàn)手機圖片上傳功能(thinkphp,mobile.js)
鏈接URL:http://muchs.cn/article32/ipphsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、商城網(wǎng)站、Google、企業(yè)網(wǎng)站制作、品牌網(wǎng)站制作、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)