在PHP中使用ajax上传图像

时间:2013-09-06 06:37:46

标签: php ajax image

尝试使用带有页面刷新的ajax上传图像。要上传文件,需要多次点击按钮。任何一个PLZ解决这个问题

<script language="javascript">
        var loadImageWhite  =   '<img src="images/loader_small_white.gif"  alt="Loading.."/>';
            function imageUpload(id,upload_dir) {
                var loadImg =   loadImageWhite; 
                var imgVal  =   $('#hid_img_val'+id).val();
                if(imgVal)
                {
                    removeImage(imgVal,id);
                    imgVal      =   '';
                }
                var uploader = document.getElementById('uploader'+id);
                upclick(
                 {
                  element: uploader,
                  dataname: 'Filedata'+id,
                  action: 'ajaximage.php?file_name=Filedata'+id+'&file_path=registration_images/'+upload_dir+'/', 
                  onstart:
                    function(filename)
                    {
                        //$('#save_btn'+id).attr('disabled','disabled');    
                        $('#hid_img'+id).html(loadImg);
                    },
                  oncomplete:
                    function(response_data) 
                    {
                        $('#hid_img_val'+id).val(response_data);
                        $('#hid_img'+id).html('<div id="hid_img" style="height:30px;"><div style="float:left;padding-right:10px;"><img width="30" height="30" src="registration_images/'+upload_dir+'/'+response_data+'"></div><div style="padding-top:10px;"><a href="javascript:;" onclick="removeImage(\''+response_data+'\',\''+id+'\',\''+upload_dir+'\');">Remove</a></div></div>');
                        //$('#save_btn'+id).removeAttr('disabled'); 
                    }
                 });
                 $('#Filedata'+id).attr("onClick","imageUpload('"+id+"');");    
            }

0 个答案:

没有答案