1

I present a dialog with a form to upload a file.

When OK is clicked, the selected file should upload.

How do I do this with jquery and PHP?

Code:

    if(act=='exchangePic')
{               
    $("#dialog").attr('title','Change picture ').dialog({buttons:{'ok':{class:'btn',text:'Ok',click:function(){
    $('#imgHolder_'+picture_id).css({'background-color':''});
    $(this).dialog('close');    

    }}}, show:'fade',hide:'explode',width:'380px',modal:true,closeText:' X  '}).html("<form><input type='file' id='newUpload' name='newUpload' class='upfile'/></form>");

}//end of act=='exchangePic'
3
  • 1
    You cannot upload files using XMLHttpRequest (AJAX). Try to use blueimp.github.com/jQuery-File-Upload Commented Jan 9, 2013 at 16:53
  • 4
    @Arunkumar — You can. You just need a browser that supports the File API. Such: developer.mozilla.org/en-US/docs/… Commented Jan 9, 2013 at 16:57
  • @Arunkumar, XMLHttpRequest v 2.0 is able to handle files. You could also use jQuery form plugin if you want. It's really simple. malsup.com/jquery/form Commented Jan 9, 2013 at 17:15

1 Answer 1

1

Why write everything yourself? Plupload is a solid open source uploader with lots of great features.

Here is the jquery sample

Plupload features

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Looks so nice! I'll try it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.