1

Ok, I hope this will be my last question in a series of Q's regarding dynamic file upload.

I'm using AjaxFileUpload Plugin and try to work with the FORM data in my uploader.php. The problem is that both $_POST and $_FILES is NULL.

This is my HTML code:

  <form id="uploadForm" enctype="multipart/form-data" action="" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <input type="hidden" name="current_path" value="<?php echo $fb->relative_url; ?>" />
    <input id="uploadFile" name="uploadFile" type="file" />
    <input type="button" class="button uploadImage" value="<?php _e('Upload File') ?>" /> <br />
  </form> 

And this is my JS script:

  //File upload
    jQuery('.uploadImage').live('click',function() {
    ajaxFileUpload();
  });

  (...)

  function ajaxFileUpload() {
    jQuery.ajaxFileUpload ( {
        url:'../wp-content/plugins/wp-filebrowser/uploader.php', 
        secureuri:false,
        fileElementId:'uploadFile',
        dataType: 'json',
        success: function (data, status) {
            alert('Error: ' + data.error + ' - Respons: ' + data.respons)
        },
        error: function (data, status, e) {
            alert('Error: ' + e);
        }
      }
    )
    return false;   
  }

To test that I data is submited, I have the following PHP code:

  $data['error']    = $_POST['current_path'];  // Gives me NULL
  $data['respons']  = $_FILES['uploadFile']['name']; // Gives me NULL

  // Return result in json 
  echo json_encode($data);  

UPDATE

After very good help from Pekka (with his good set of eyes), I have got it working! The code is updated with the correct code.

1 Answer 1

3

You are assigning

fileElementId:'uploadFile',

but your file field doesn't in fact have that ID.

And your PHP script should look in

$_FILES["uploadFile"]["name"]
Sign up to request clarification or add additional context in comments.

9 Comments

Well spotted! I added the ID but still get the same result :(
@STeven what does a print_r($_POST) yield?
@Steven also, more importantly, shouldn't it be $_FILES['uploadFile']['name'];?
I can't see any output from PHP because it's all in an Iframe (I think). I've tested oouputting the content in a IFrame I hadded in HTML code, and all works fine. It only breaks when I try to use the Ajax plugin. I've also addded link to mye files if you want to download and have a look.
@Steven see my last comment, that's more important I think
|

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.