台灣最大裝潢接案平台
輕鬆接案網
清潔公司專精高難度抓漏工程,近30年經驗
快速找出問題所在,品質絕佳。

首頁  •  j2h 論壇 • 程式設計討論     • 

[JQuery] Jquery+PHP - 檔案上傳

房東:阿副
發表時間:2011-05-19
[檢舉]


HTML 部份


<head>

    <script type="text/javascript" src="ajaxupload.3.5.js"></script>

</head>


<form action="upload.do" method="post" enctype="multipart/form-data">

    <img name="img1" id="img1" width="80" height="80">

    <span id="button1" class="button">上傳</span>

</form>




JS 部份


<script type= "text/javascript">

$(document).ready(function(){

    var button = $(\'#button1\'), interval;

    new AjaxUpload(button,{

        action: \'rpc.php\', // I disabled uploads in this example for security reasons

        name: \'myfile\',

        data: {

            act: \'<{php}>echo base64_encode(\'上傳檔案\')<{/php}>\',

        },

        onSubmit : function(file, ext){

            // change button text, when user selects file           

            button.text(\'檔案上傳中\');

            // If you want to allow uploading only 1 file at time,

            // you can disable upload button

            this.disable();

            // Uploding -> Uploading. -> Uploading...

            interval = window.setInterval(function(){

                var text = button.text();

                if (text.length < 13){

                    button.text(text + \'.\');                   

                } else {

                    button.text(\'檔案上傳中\');               

                }

            }, 200);

        },

        onComplete: function(file, response){

            button.text(\'上傳\');

            window.clearInterval(interval);

            // enable upload button

            this.enable();

            // add file to the list

            $(\'#img2\').attr("src", function() {

                return "../tmp/" + file;

            });

        }

    });

});

</script>




PHP 部份


與一般上傳檔案的處理方式相同。





  • 贊助網站       

    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!
    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務



  •  共 0 人回應

    姓名:
    佈告內容: