jquery form plugin in wordpress to upload an image file does not work as
expected
Trying to use the jquery form plugin in a worpress site .
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=" Upload "
class="btn_upload"> Upload </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 has
$photoimg = trim($_POST['photoimg']);
echo 'got it';
If I do not select any file , I get the result as expected. But if I
select an image file then the error message says - "Undefined index:
photoimg in line ...."
How to make it work correctly?
No comments:
Post a Comment