《PHP教程:thinkphp jquery實(shí)現(xiàn)圖片上傳和預(yù)覽效果》要點(diǎn):
本文介紹了PHP教程:thinkphp jquery實(shí)現(xiàn)圖片上傳和預(yù)覽效果,希望對您有用。如果有疑問,可以聯(lián)系我們。
相關(guān)主題:thinkphp教程
PHP學(xué)習(xí)先上效果圖:
PHP學(xué)習(xí)
PHP學(xué)習(xí)那個file按鈕樣式先忽略
PHP學(xué)習(xí)點(diǎn)擊選擇圖片(瀏覽),隨便選一張圖片
PHP學(xué)習(xí)
PHP學(xué)習(xí)js代碼如下
PHP學(xué)習(xí)
//上傳圖片立即預(yù)覽
function PreviewImage(imgFile) {
var filextension = imgFile.value.substring(imgFile.value
.lastIndexOf("."), imgFile.value.length);
filextension = filextension.toLowerCase();
if ((filextension != '.jpg') && (filextension != '.gif')
&& (filextension != '.jpeg') && (filextension != '.png')
&& (filextension != '.bmp')) {
alert("對不起,系統(tǒng)僅支持標(biāo)準(zhǔn)格式的照片,請您調(diào)整格式后重新上傳,謝謝 !");
imgFile.focus();
} else {
var path;
if (document.all)//IE
{
imgFile.select();
path = document.selection.createRange().text;
document.getElementById("photo_info").innerHTML = "";
document.getElementById("photo_info").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\""
+ path + "\")";//使用濾鏡效果
} else//FF
{
path = window.URL.createObjectURL(imgFile.files[0]);// FF 7.0以上
//path = imgFile.files[0].getAsDataURL();// FF 3.0
document.getElementById("photo_info").innerHTML = "<img id='img1' width='120px' height='100px' src='"+path+"'/>";
//document.getElementById("img1").src = path;
}
}
}
PHP學(xué)習(xí)html代碼,其實(shí)不重要啦
PHP學(xué)習(xí)
<div class="form-group has-success has-feedback">
<label for="info_photo" class="col-sm-2 control-label">物品圖片</label>
<div class="col-sm-10">
<span class="btn btn-success btn-file"> 選擇圖片 <span
class="glyphicon glyphicon-picture" aria-hidden="true"></span>
<input type="file" name="info_photo" value="" id="info_photo"
onchange='PreviewImage(this)' />
</span>
</div>
</div>
<div class="form-group has-success has-feedback">
<label for="info_desc" class="col-sm-2 control-label"><span
style="color: red;">* </span>?詳細(xì)描述</label>
<div class="col-sm-10">
<textarea class="form-control" rows="5" id="info_desc"
name="info_desc" placeholder="如需補(bǔ)充,請?zhí)顚?.." title="可包含中文數(shù)字和常用字符"></textarea>
<div id="photo_info" class="photo_info"></div>
</div>
</div>
PHP學(xué)習(xí)css代碼就不上了啊
順便補(bǔ)充一下thinkphp上傳圖片代碼,把整個發(fā)布消息都拷過了算了
PHP學(xué)習(xí)
public function loseThing(){
$m=M('info');
$m->create();
$upload = new \Think\Upload();// 實(shí)例化上傳類
$upload->maxSize = 3145728 ;// 設(shè)置附件上傳大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg','bmp');// 設(shè)置附件上傳類型
$upload->rootPath = './Public/';
$upload->savePath = '/Uploads/'; // 設(shè)置附件上傳目錄
$upload->autoSub = false;
// 上傳文件
$info = $upload->upload();
if($info) {
// 上傳成功
foreach($info as $file){
$m->info_photo=$file['savename'];
}
}
$m->create_time=date('Y-m-d H:i:s',time());
$m->uid=$_SESSION['id'];
$m->username=$_SESSION['username'];
/* $m->user_img=$_SESSION['filename']; */
$m->info_type="尋物啟事";//信息類型為失物
$lastId=$m->add();
if($lastId){
$this->success('發(fā)布成功');
}else{
$this->error('發(fā)布失敗,請先登錄');
}
}
PHP學(xué)習(xí)以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持維易PHP.
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/2510.html