wordpress中的jquery表单插件上传图像文件无法按预期工作

时间:2013-09-14 14:17:57

标签: jquery file-upload jquery-forms-plugin

尝试在worpress网站中使用jquery form plugin

HTML:

<form id="imageform" method="post"  action="<?php bloginfo('template_directory')?>/ajaximage.php " enctype="multipart/form-data" accept-charset="utf-8" >

Upload image:

<input type="file" name="photoimg" id="photoimg" value=""  />
</form>

<button value="&nbsp;Upload&nbsp;" class="btn_upload">&nbsp;Upload&nbsp;</button>   
    <div id='preview'></div><!-- end of id preview-->

JS:

$(document).ready(function(){

   $(".btn_upload").click(function(){

        $("#preview").html(''); 

    $(".result_upload").html('<img src="'+loc+'/images/ajax-loader.gif"  alt="wait.."/>');


    $("#imageform").ajaxForm({
                            target: '#preview'

            }).submit();

            });

    }); 

ajaximage.php有

  $photoimg = trim($_POST['photoimg']);
  echo 'got it';

如果我没有选择任何文件,我会按预期得到结果。但是如果我选择一个图像文件,那么错误信息会显示 - “Undefined index:photoimg in line ....”

如何让它正常工作?

1 个答案:

答案 0 :(得分:1)

您是否尝试过$ _FILES而不是$ _POST? http://php.net/manual/en/reserved.variables.files.php

(提交文件时,它在$ _FILES内引用而不是$ _POST。)