代码之家  ›  专栏  ›  技术社区  ›  Steven

AjaxFileUpload插件不检索$_Post数据

  •  0
  • Steven  · 技术社区  · 14 年前

    I faced a few days ago . 那时候我修好了,但现在它不起作用了。好吧,有些是可行的。

    AjaxFileUpload Plugin 在我的wp插件中上传文件。此插件调用 uploader.php

    我可以使用 $_FILES['uploadFile'] 但是我无法找回 $_POST['current_path'] 数据。

    不过我有个理论。当我加载上载数据的接口时,隐藏的输入字段“当前路径”为空(应该为空)。当我浏览文件夹时,隐藏的输入字段将使用jquery进行更新。

    上传文件 通过 $_POST $_FILES .

    但是为什么我能从 $x文件 而不是来自 美元邮报 ?

    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);  
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Pekka    14 年前

    但是为什么我能从$u文件而不是从$u邮件中获取数据呢?

    by design :

    在这个黑客版本中,它只提交输入元素的指定文件类型,而不提交整个表单。

    这个 jQuery form plugin