欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用jquery.form.js實(shí)現(xiàn)圖片上傳的方法

 更新時(shí)間:2016年05月05日 10:31:37   作者:314756557  
這篇文章主要介紹了使用jquery.form.js實(shí)現(xiàn)圖片上傳的方法,涉及jquery使用表單插件jquery.form.js進(jìn)行圖片上傳的提交、類型驗(yàn)證、執(zhí)行結(jié)果回調(diào)顯示等技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了使用jquery.form.js實(shí)現(xiàn)圖片上傳的方法。分享給大家供大家參考,具體如下:

testupfile2.php

<?php
header('Content-type:text/html;charset=utf-8');
include_once 'includes/common.inc.php';
 if(!empty($_FILES['upfile'])){
 //文件格式
 $image=array('image/jpg',
   'image/jpeg',
   'image/png',
   'image/pjpeg',
   'image/gif',
   'image/bmp',
   'image/x-png'
 );
$updir=$_SERVER['DOCUMENT_ROOT'].$_config['g']['baseUrl'].'/attached/images/';
$upfile=$_FILES['upfile'];
$name=$upfile['name'];
$ext=substr($upfile['name'],strpos($upfile['name'],'.'));
$upname=md5(time().rand(1, 1000)).$ext;
$type=$upfile['type'];
$size=$upfile['size'];
$tmp_name=$upfile['tmp_name'];
$error=$upfile['error'];
$ok=0;
 foreach ($image as $key=>$value) {
 if($type==$value)$ok=1;
 }
 if($ok=='1' && $error=='0'){
 move_uploaded_file($tmp_name,$updir.$upname);
 //echo '<br>'.$tmp_name.'<br>'.$upname.'<br>'.$updir.'<br>'.$ext.'上傳成功';
 //echo '上傳成功';
 echo $upname;
 //$im=$updir.$upname;
 //echo $im;
 //echo '<img src='.$updir.$upname.' />';
 //$views->assign('image',$upname);
 //$views->display('default/testupfile.html');
 }
 else echo '上傳失敗2';
}
else echo '上傳失敗1';
?>

testupfile.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<!--{$baseUrl}-->/scripts/jquery.js"></script>
<script type="text/javascript" src="<!--{$baseUrl}-->/scripts/jquery.form.js"></script>
<script type="text/javascript">
$(function(){
 //jquery.form image1
 $("#upimage").bind("click",function(){
 if($("#upfile").val()==""){
  alert("請(qǐng)選擇一個(gè)圖片文件,再點(diǎn)擊");
  return;
 }
 $("#form1").ajaxSubmit({
  url:"testupfile2.php",
  type:"POST",
  //date:"upfile=upfile",
  success:function(response){
  alert(response);
  $("#ln").empty();
  $("#ln").append("<img src='<!--{$baseUrl}-->/attached/images/"+response+"' width='100' height='60'/>");
  $("#im1").val(response);
  },
  error:function(msg){
  alert("出錯(cuò)了");
  }
 });
 });
 //jquery.form image2
 $("#upimage2").bind("click",function(){
 if($("#upfile2").val()==""){
  alert("請(qǐng)選擇一個(gè)圖片文件,再點(diǎn)擊2");
  return;
 }
 $("#form2").ajaxSubmit({
  url:"testupfile2.php",
  type:"POST",
  //date:"upfile=upfile2",
  success:function(response2){
  alert(response2);
  $("#ln2").empty();
  $("#ln2").append("<img src='<!--{$baseUrl}-->/attached/images/"+response2+"' width='100' height='60'/>");
  $("#im2").val(response2);
  },
  error:function(msg){
  alert("出錯(cuò)了");
  }
 });
 });
});
</script>
</head>
<body>
文件上傳
<form enctype="multipart/form-data" id="form1" method="post" action="">
文件:
 <input type="file" name="upfile" id="upfile"><input type="button" id="upimage" value="圖片上傳1">
 <input type="text" name="im1" id="im1" value="" />
</form>
<form enctype="multipart/form-data" id="form2" method="post" action="">
文件:
 <input type="file" name="upfile" id="upfile2"><input type="button" id="upimage2" value="圖片上傳2">
 <input type="text" name="im2" id="im2" value="" />
</form>
<div id="ln">tu</div><br>
<div id="ln2">tu2</div>
</body>
</html>

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery form操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery切換特效與技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》、《jquery選擇器用法總結(jié)》及《jQuery常用插件及用法總結(jié)

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • jQuery UI-Draggable 參數(shù)集合

    jQuery UI-Draggable 參數(shù)集合

    jQuery UI-Draggable常用參數(shù)集合。
    2010-01-01
  • jQuery插件imgAreaSelect基礎(chǔ)講解

    jQuery插件imgAreaSelect基礎(chǔ)講解

    關(guān)于ImgAreaSelect, 是一jQuery插件,它支持用戶通過(guò)鼠標(biāo)拖曳選擇圖片的一部分,如圖片拖曳、圖片編輯等。下面通過(guò)本文給大家介紹jQuery插件imgAreaSelect基礎(chǔ)講解,需要的的朋友參考下吧
    2017-05-05
  • jQuery源碼分析之Event事件分析

    jQuery源碼分析之Event事件分析

    對(duì)于javascript事件擴(kuò)展,所有的lib都差不多。和jquery和prototype,yui和Ext,其要解決的首要問(wèn)題是兼容性,所有 lib都會(huì)對(duì)event進(jìn)行包裹,統(tǒng)一其屬性解決其兼容性。
    2010-06-06
  • json格式的javascript對(duì)象用法分析

    json格式的javascript對(duì)象用法分析

    這篇文章主要介紹了json格式的javascript對(duì)象用法,結(jié)合實(shí)例形式總結(jié)分析了javascript針對(duì)json格式數(shù)據(jù)操作的常見(jiàn)技巧,需要的朋友可以參考下
    2016-07-07
  • jQuery實(shí)現(xiàn)獲取當(dāng)前鼠標(biāo)位置并輸出功能示例

    jQuery實(shí)現(xiàn)獲取當(dāng)前鼠標(biāo)位置并輸出功能示例

    這篇文章主要介紹了jQuery實(shí)現(xiàn)獲取當(dāng)前鼠標(biāo)位置并輸出功能,涉及jQuery事件響應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-01-01
  • jQuery焦點(diǎn)圖輪播特效代碼分享(3款)

    jQuery焦點(diǎn)圖輪播特效代碼分享(3款)

    這篇文章主要介紹了jQuery焦點(diǎn)圖輪播特效,jQuery cxSlide實(shí)現(xiàn)的三款多功能大氣焦點(diǎn)圖輪播特效源碼,是一段擁有三種不同風(fēng)格和效果的焦點(diǎn)圖輪播代碼,還可以使用鼠標(biāo)的滾輪控制圖片的縮放,推薦給大家,有需要的小伙伴可以參考下
    2015-09-09
  • jQuery 計(jì)算iframe 窗口大小的方法

    jQuery 計(jì)算iframe 窗口大小的方法

    這篇文章主要介紹了jQuery如何計(jì)算iframe窗口大小,需要的朋友可以參考下
    2014-05-05
  • jQuery.autocomplete 支持中文輸入(firefox)修正方法

    jQuery.autocomplete 支持中文輸入(firefox)修正方法

    jQuery.autocomplete 是jquery的流行插件,,能夠很好的實(shí)現(xiàn)輸入框的自動(dòng)完成(autocomplete)、建議提示(input suggest)功能,支持ajax數(shù)據(jù)加載。
    2011-03-03
  • jQuery分組選擇器簡(jiǎn)單用法示例

    jQuery分組選擇器簡(jiǎn)單用法示例

    這篇文章主要介紹了jQuery分組選擇器簡(jiǎn)單用法,結(jié)合實(shí)例形式分析了使用jQuery分組選擇器動(dòng)態(tài)設(shè)置頁(yè)面元素屬性相關(guān)操作技巧,需要的朋友可以參考下
    2019-04-04
  • 淺談jquery事件處理

    淺談jquery事件處理

    這篇文章主要簡(jiǎn)單介紹了jquery事件處理,十分的實(shí)用,有需要的小伙伴可以參考下。
    2015-04-04

最新評(píng)論