js和iframe實現圖片無刷新上傳【PHP技術】

 html代碼

 

  1. <html> 
  2.     <head> 
  3.         <meta http-equiv="content-type" content="text/html;charset=utf-8"> 
  4.         <title>js和iframe實現圖片無刷新上傳</title> 
  5.         <style type="text/css"> 
  6.             #h1{ 
  7.                 text-align:center; 
  8.             } 
  9.             <!--隱藏iframe--> 
  10.             iframe{ 
  11.                     display:none; 
  12.             } 
  13.         </style> 
  14.     </head> 
  15.     <body> 
  16.         <h1 id='h1'>js和iframe實現圖片無刷新上傳</h1> 
  17.         <h1 id='h1'><script>document.write(new Date())</script></h1> 
  18.         <form action="./file.php" method="post" enctype="multipart/form-data" target="upload"> 
  19.             <input type="file" name="file" id="file"/> 
  20.             <br> 
  21.             <input type="submit" name="sub" value="提交"/> 
  22.              
  23.         </form> 
  24.             <img id="imgid" name="imgid"> 
  25.             <iframe src="" name="upload"> 
  26.             </iframe> 
  27.          
  28.     </body> 
  29.     <script>        
  30.     </script> 
  31.  
  32. </html> 

 

php代碼

 

  1. <?php 
  2. $sfile=$_FILES['file']['tmp_name']; 
  3. $dfile=$_FILES['file']['name']; 
  4. if(move_uploaded_file($sfile,$dfile)){ 
  5.         echo "<script>imgobj=window.top.document.getElementById('imgid');imgobj.src='$dfile'</script>"

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章