I making an upload form for *.pdf
HTML:
<div class="form-group">
<label class="col-md-3 control-label" for="file_sm">Upload File:</label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-primary btn-file">
Browse <input type="file" name="file_sm[]" id="file_sm" name="file_sm" accept="application/pdf"/>
</span>
</span>
<input type="text" class="form-control" readonly>
</div>
</div>
</div>
and using JQuery for $_POST the data to sm.input.php
$("#save-sm").bind("click", function(event) {
var url = "sm.input.php";
var v_file_sm = $('input:file[name=file_sm]').val();
// sending for process
$.post(url, {file_sm: v_file_sm, id: id_sm} ,function() {
// show data <div id="data-sm"></div>
$("#data-sm").load(main);
// hide modal dialog
$('#dialog-sm').modal('hide');
});
});
and inside sm.input.php
file:
if(isset($_POST['save_sm'])){
foreach($_FILES['file_sm']['name'] as $key => $val){
$name = $_FILES['file_sm']['name'][$key];
$tmp = $_FILES['file_sm']['tmp_name'][$key];
$file_size = $_FILES['file_sm']['size'][$key];
if($file_size < 50000){
if(trim($name)!=''){
$new_name = date('YmdHis').'_'.$name; //rename file
if(move_uploaded_file($tmp,'/upload/'.$new_name)){
$file_sm = $new_name;
}
}
} else {
echo "MAX 50KB";
}
}
}
why input:file selector JQuery is not working for me? the file didn't uploading and the php server can't get the file name.. whats wrong with my code?
I read about AJAX file uploading, but I still cant understand how to implement on my code :(