jquery - PHP input type file field being submitted, file isnt -
i have following form.
<form action="picture.php" method="post" class="pic_form"> <span class="picture_box"> <input type="file" accept="image/*" name="pic_upload" class="picture_upload_input" /> <p class="upload_info">only file types of extensions gif, jpg, png , svg allowed. maximum file size 15mb. if file larger 15mb, not upload.</p> </span> <input type="hidden" name="uid" value="<?php echo $_session['userid']; ?>" /> <input type="button" name="upload_button" value="upload" class="upload_button" /> </form>
i validate file set , it's of correct type , size using jquery. when submit form (using jquery), field posted
$_post['pic_upload']
this returns true.
however, file isn't posted
$_files['custom_pic_upload']
this returns false ,
var_dump($_files['custom_pic_upload']);
returns null.
how make file upload?
your form needs attribute enctype
, https://developer.mozilla.org/en-us/docs/web/html/element/form.
multipart/form-data: value used element type attribute set "file".
<form action="picture.php" method="post" class="pic_form" enctype="multipart/form-data"> <span class="picture_box"> <input type="file" accept="image/*" name="pic_upload" class="picture_upload_input" /> <p class="upload_info">only file types of extensions gif, jpg, png , svg allowed. maximum file size 15mb. if file larger 15mb, not upload.</p> </span> <input type="hidden" name="uid" value="<?php echo $_session['userid']; ?>" /> <input type="submit" name="upload_button" value="upload" class="upload_button" /> </form> <script type='text/javascript'> $('.upload_button').click(function(){ var upload_ver_val = $('.picture_upload_input').val(); if (upload_ver_val == '') { alert("please upload image!"); return false; } else { var ext = $('.picture_upload_input').val().split('.').pop().tolowercase(); if($.inarray(ext, ['gif','png','jpg','jpeg','svg']) == -1) { alert('only file types of extensions; gif, jpg, png , svg allowed!'); return false; } else { $('.prof_pic_form').submit(); } } }); </script>
other threads on topic , tutorial.
what enctype='multipart/form-data' mean?
http://www.tizag.com/phpt/fileupload.php
also name of php value name
attribute, not class
, pic_upload
.
Comments
Post a Comment