0

I want to upload files using jquery without using submit. I'm trying to do it wiht $.post but I'm not geting the $FILES['myfile']['name'] and $['myfile']['tmp_name'] that I need for php. Here are my codes. Please help.

 <form method="post" enctype="multipart/form-data">
 <input type='file' id='myfile' name='myfile' />
 <input type='button' id='submit' value='Submit' onclick='new_data()' />
 </form>

 function new_data(){
  action = 'new';
  var file = $('#myfile').val();
  $.post('upload.php',{action:action,file:file},function(data){('#post-values').html(data)}); 
 }

 <?php
 if($_POST['action']=='new'){
    echo $_FILES['file']['name'];
    echo $_FILES['file']['tmp_name'];
 }
 ?>
rain
  • 95
  • 3
  • 13
  • 1
    `$_FILES['file']` study that and look at your file's name attribute. – Funk Forty Niner Dec 08 '14 at 23:06
  • possible duplicate of [How can I upload files asynchronously with jQuery?](http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery) –  Dec 08 '14 at 23:07
  • Ive tried this using $.ajax() but I still could not get the file attributes. I need it in order to upload files to my server with out refreshing the page. – rain Dec 09 '14 at 03:37

0 Answers0