2010-09-13 42 views
0

這與I faced a few days ago幾乎完全相同。我修好了,但現在不再工作了。那麼,它的一些作品。

我使用AjaxFileUpload Plugin上傳我的WP插件中的文件。這個插件調用uploader.php來處理上傳表單。

我能夠使用$_FILES['uploadFile']獲得文件名(和其他數據),但我無法檢索$_POST['current_path']數據。

雖然我有一個理論。當我加載接口上傳數據時,隱藏的輸入字段'current_path'是空的(應該是這樣)。在瀏覽我的文件夾時,使用jQuery更新隱藏的輸入字段。

當我點擊上傳按鈕時,Ajax File Upload插件將上傳表單中的數據取出,並將數據傳遞到uploader.php$_POST$_FILES

但爲什麼我能從$_FILES而不是從$_POST獲取數據?

這裏是我的代碼:

的Javascript

//File upload functions 
    // Remove feedback message on upload click 
    jQuery('.uploadImage').live('click',function() { 
     ajaxFileUpload(); 
    }); 

    (...) 

    //Lets upload the file by using Ajax uploader plugin 
    function ajaxFileUpload() { 
    alert(jQuery('input[type=hidden][name=current_path]').val()) //Shows me the correct current path 
    jQuery.ajaxFileUpload ({ 
     url:'../wp-content/plugins/wp-filebrowser/uploader.php', 
     secureuri:false, 
     fileElementId:'uploadFile', 
     dataType: 'json', 
     success: function (data) { 
      if(data.error != '') { 
       alert(data.error); 
      } else { 
       alert(data.respons); 
      } 
     }, 
     error: function (e) { 
      jQuery('#uploadOutput').addClass('error').html('Error: ' + e).show(); 
     }, 
     complete: function() { 
      // Update file list 
     } 
     } 
    ) 
    return false; 
    } 

HTML

<form id="uploadForm" enctype="multipart/form-data" action="" method="POST"> 
    <input type="hidden" id="current_path" 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> 

PHP

$this->current_path = $_POST['current_path']; 
$this->data['error'] = $_FILES['uploadFile']['name']; //Just for testing 
$this->data['respons'] = "Filename: ".$_POST['current_path']; 

echo json_encode($this->data); 

回答

3

但爲什麼我能夠從$ _FILES獲取數據而不是從$ _POST獲取數據?

因爲您沒有提交表單,只有文件輸入元素。

這似乎是插件的行爲by design

在被黑的版本,其提交的輸入元素指定的文件類型只,而不是整個表單

jQuery form plugin既可以做,也許這有幫助。

+0

狗屎。你是對的。我還沒有成功使用jQuery表單插件,但會給它另一個鏡頭。 – Steven 2010-09-13 11:23:50