《PHP教程:PHP實(shí)現(xiàn)上傳多圖即時(shí)顯示與即時(shí)刪除的方法》要點(diǎn):
本文介紹了PHP教程:PHP實(shí)現(xiàn)上傳多圖即時(shí)顯示與即時(shí)刪除的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP應(yīng)用本文實(shí)例講述了PHP實(shí)現(xiàn)上傳多圖即時(shí)顯示與即時(shí)刪除的方法.分享給大家供大家參考,具體如下:
PHP應(yīng)用
PHP應(yīng)用就像這樣的,每選擇一個(gè)圖片就會(huì)即時(shí)顯示出來,附加到右邊,也可以隨意刪除一個(gè)元素.
PHP應(yīng)用其實(shí)是,當(dāng)type=file的input框框的onchange事件===》》》post數(shù)據(jù)提交到隱藏的ifram(form表單的target指定)===》》》接收到post數(shù)據(jù)的直接 echo??? script標(biāo)簽來返回?cái)?shù)據(jù)到前端頁面并且賦值,然后存儲圖片路徑也是用隱藏域?qū)崿F(xiàn):
PHP應(yīng)用HTML:
PHP應(yīng)用
<!doctype html>
<html lang="cn">
<include file="Public/head"/>
<body>
<include file="Public/nav"/>
<iframe name="upload_url" style="display:none"></iframe>
<div class="wlog">
<div class="wlog_t cf">
<b>寫日志</b>
</div>
<div class="wlog_c">
<form class="cf" id="myform" target="" enctype="multipart/form-data" action="" method="post">
<div class="wlog_l">
<textarea id="content" name="data[content]"></textarea>
<input type="hidden" id="step" value="1" name="data[step]" />
</div>
<div class="wlog_r">
<h2>選擇裝修階段</h2>
<b class="cur" mine="1" style="line-height:20px;">準(zhǔn)備開工</b>
<b mine="2" >水電</b>
<b mine="3">泥木</b>
<b mine="4">油漆</b>
<b mine="5">竣工</b>
<b mine="6">軟裝</b>
<!-- <input type="hidden" value="準(zhǔn)備開工"> -->
</div>
<div class="wlog_f cf">
<h2><b>上傳圖片</b>選擇裝修過程中的照片,每張低于5M,支持JPG/JPEG/PNG格式,最多9張</h2>
<div class="wlog_p cf">
<a href=";" rel="external nofollow" ><img src="__PUBLIC__/home/images/2016-10-29_231703.png" alt=""><input onchange="submitimg()" type="file" name="thumb"/></a>
<div id="addimg"></div>
<!-- <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b>
<b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b>
<b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b>
<b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b>
<b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b>
<b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b>
<b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b>
<b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> -->
</div>
</div>
<div class="wlog_sm"><input type="botton" onclick="return goods_form_submit()" readonly="readonly" value="發(fā)布日志"></div>
</form>
</div>
</div>
<include file="Public/footer"/>
<script type="text/javascript">
function submitimg(){
$("#myform").attr('target','upload_url');
$("#myform").attr('action',"{:U('Journal/submitimg')}");
$("#myform").submit();
}
function goods_form_submit()
{
if(!$('#content').val()){
alert('請?zhí)顚懭罩?);
return false;
}
$('#myform').attr('target','');
$('#myform').attr('action','');
$('#myform').submit();
}
function callblack_img(path,uid)
{ var html="";
var dir = "{:C(FILE_PATH)}";
var html ='<b><img src='+dir+path+'><i>x</i><input type="hidden" value="'+path+'" name="thumb['+uid+']"></b>';
$('#addimg').append(html);
}
</script>
<script type="text/javascript" src="__PUBLIC__/home/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/home/js/basis.js"></script>
<script>
$(function(){
$('.wlog_r b').click(function(event) {
$(this).addClass('cur').siblings('b').removeClass('cur');
$('.wlog_r input[type=hidden]').val($(this).text());
});
$("#addimg").delegate("i","click",function () {
$(this).parent("b").remove();
})
})
$("b").click(function(){
var value =$(this).attr('mine');
$("#step").val(value);
})
</script>
</body>
</html>
PHP應(yīng)用控制器(返回被選中的圖片(已經(jīng)上傳)在服務(wù)器之中的路徑):
PHP應(yīng)用
public function submitimg(){
if(IS_POST){
$data = I('post.data');//獲取post數(shù)據(jù)
$res = fab_upload($_FILES);//上傳文件
$uid=uniqid();
$res=$res['thumb'];
if($res){
echo "<script>parent.callblack_img('{$res}','{$uid}');</script>";
}
}
}
PHP應(yīng)用真正的最后接收表單數(shù)據(jù)并且存入數(shù)據(jù)庫的函數(shù):
PHP應(yīng)用
public function add_journal(){
if(IS_POST){
var_dump($_POST);die;
}else{
$this->display();
}
}
PHP應(yīng)用更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結(jié)》、《PHP圖形與圖片操作技巧匯總》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
PHP應(yīng)用希望本文所述對大家PHP程序設(shè)計(jì)有所幫助.
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/815.html