ajax檔案上傳

來源:互聯網
上載者:User
 代碼如下 複製代碼

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>ajax檔案上傳</title>
<style type="text/css教程">
#f1_upload_process { display:none;}
</style>
<script language="網頁特效" type="text/javascript">
<!--

function $(id)
{
 return document.getelementbyid(id);
}

function startupload(){
      if( $('myfile').value =='' )
   {
    alert('請選擇要上傳圖片!');
    return false;
   }
   var array = $('myfile').value.split('.');
   var ext = array[1].tolowercase();  
   if( ext =="gif" || ext =="jpg" || ext =="png" )
   {   
    $('f1_upload_process').style.display = 'block';
    $('f1_upload_form').style.display = 'block';
    return true;
   }
   else
   {
   alert('只允許上傳gif jpg png格式影像檔!');
   return false; 
   }
}

function stopupload(success,pic){
      var result = '';
      if (success ==1 ){
   result ='<img src='+pic+' />';
   $('logo').value=pic;
      }
      else {
         result = '<span class="emsg">logo圖片上傳失敗,請聯絡開發人員!</span><br/><br/>';
      }
      $('f1_upload_process').style.display = 'none';
      $('f1_upload_form').innerhtml = result + '<br /><label><input name="myfile" type="file" size="30" /></label><label><input type="submit" name="submitbtn" class="sbtn" value="上傳圖片" /></label>';
      $('f1_upload_form').style.display = 'block';    
      return true;  
}

//-->
</script>
</head>

<body>
<form action="upload.php教程" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="javascript:return startupload();" >
     <span id="f1_upload_process"><img src="loader.gif" /></span>
     <span id="f1_upload_form" align="center">
       <input name="myfile" type="file" id="myfile" size="30" />  
       <input type="submit" name="submitbtn" class="sbtn" value="上傳圖片" />
       
     </span>
    
     <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
 (可上傳 gif,jpg,png)
</form>
</body>
</html>

upload.php

 代碼如下 複製代碼

<?php
   $destination_path = '../../upfile/jianjulogo/';//getcwd().directory_separator;

   $result = 0;
  
   $target_path = $destination_path . basename( $_files['myfile']['name']);

   if(@move_uploaded_file($_files['myfile']['tmp_name'], $target_path)) {
      $result = 1;
   }
   echo $target_path;
   sleep(1);


?>
<script language="javascript" type="text/javascript">window.top.window.stopupload(<?php echo $result; ?>,'<?=$target_path?>');</script>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.