Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

php - AjaxFileUpload Plugin does not retrieve $_POST or $_FILES data

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...