javascript - Get fileName in jquery Upload plugin for append it in html form -
i have issue jquery upload plugin, using jquery upload file plugin version: 3.1.10 http://hayageek.com , problem filename wich want copy database.
i have html form little complex texts
, checkboxes
, etc.
a part of form
looks this:
<form> <input type="text" name="titlu" value="marcel"> <div id="incarcareimagine">upload image</div> <button type="button" onclick="showvalues()">publish</button> </form> <script> function showvalues() { var str = $( "form" ).serialize(); $( "#results" ).html( str ); var datastring = "results="+ str; $.post('motor/parser_incarcare.php',datastring,function(theresponse){ //alert('data sended php'); //shows data php response }); } </script> <script src="js/jquery.uploadfile.min.js"></script> <script> $(document).ready(function() { var settings = { url: "upload.php", method: "post", allowedtypes:"jpg,png,jpeg", filename: "myfile", multiple: false, onsuccess:function(files,data,xhr){} } $("#incarcareimagine").uploadfile(settings); }); </script>
file upload plugin here: https://rawgit.com/hayageek/jquery-upload-file/master/js/jquery.uploadfile.min.js
this script on succes of upload image auto generating contet under #incarcareimagine
1). the_name_of_the_uploaded_file.jpg
, progress bar under text.
my question how generate inside of <form>
child this: <input type='hidden' name='image' value='the_name_of_the_uploaded_file.jpg'>
my upload.php looks like:
$director_img = "fisiere_pub/img/"; if(isset($_files["myfile2"])) { $ret2 = array(); $error =$_files["myfile2"]["error"]; { if(!is_array($_files["myfile2"]['name'])) //single file { $filename = $_files["myfile2"]["name"]; move_uploaded_file($_files["myfile2"]["tmp_name"],$director_img. $_files["myfile2"]["name"]); //echo "<br> error: ".$_files["myfile"]["error"]; $ret2[$filename]= $director_img.$filename; } else { $filecount = count($_files["myfile2"]['name']); for($i=0; $i < $filecount; $i++) { $filename = $_files["myfile2"]["name"][$i]; $ret2[$filename]= $director_img.$filename; move_uploaded_file($_files["myfile2"]["tmp_name"][$i],$director_img.$filename ); } } } echo json_encode($ret2); }
so in end have complete form
, ready sending complete data via ajax - serialize()
php parser
copy wanted data mysql database
thanks in advance team!
not sure why need (can't name php side?) if want add along lines of:
function showvalues() { $("form").find("*[name=image]").remove(); var field = $("<input type='hidden' name='image' value=''>"); field.val($("form").find('input[type=file]').val()); $("form").append(field); var str = $( "form" ).serialize();
Comments
Post a Comment