9
$.post('image.php', { image:form.image.value } <form id="form" enctype="multipart/form-data"> <input type="file" id="image" name="image"/> 

PHP->isset($_FILES['file'])

How to use $.post() to post $_FILES inside of form tag?
Do I still need include enctype or do I need use AJAX, and how can I do that?

6
  • sorry, it's impossible - safety reasons Commented Aug 8, 2013 at 13:30
  • 1
    @picios It's not impossible, anymore. But, is limited to modern browsers. Commented Aug 8, 2013 at 13:31
  • @Jonathan Lonowski yes, but if you're developer, you don't want to do such things Commented Aug 8, 2013 at 13:33
  • i have email and password need to check and post back, hmm... this is going to be hard Commented Aug 8, 2013 at 13:33
  • @BenWong Don't be discouraged! We will help you! Commented Aug 8, 2013 at 13:34

2 Answers 2

7

Use jQuery form plugin to AJAX submit the form with files. http://malsup.com/jquery/form/

In JS

$('#form').ajaxSubmit({ success: function(response) { console.log(response); } }); 

in PHP

// after doing upload work etc header('Content-type: text/json'); echo json_encode(['message' => 'Some message or param whatever']); die(); 

Full docs and examples: http://malsup.com/jquery/form/#ajaxSubmit

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

3 Comments

if i use plug in, how to post message back from php?
It's treated as a normal AJAX call - I'll edit the answer to show you how
thx a lot! let me try it
0

Just submit the form!

$('form#form').submit(); 

For AJAX Upload read this answer

2 Comments

he's talking about ajax post
Maybe after changing his question. Thanks for downvote.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.