I have a form to fill and write files in the database passing the data by ajax but the file is not arriving.
The form:
<script src="jquery.min.224.js"></script>
$("#documento").click(function(e) {
e.preventDefault();
var text1 = $("#arqnome").val();
var text2 = $("#arq").val();
$.ajax({
type: "POST",
url: "arquivo.php",
data: { documento: $(this).val(), arqnome: text1, arq: text2 }
})
.done(function(data){
$("#documento_e").html(data);
//$("#form")[0].form.reset();
});
});
<form id="form_docs" method="post" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
Tipo de Arquivo:<br />
<input type="text" name="arqnome" id="arqnome">
</td>
<td>
Selecionar Arquivo:<br />
<input type="file" name="arq" id="arq">
</td>
<td>
<button type="button" id="documento" name="documento">Gravar</button>
</td>
</tr>
</tbody>
</table>
</form>
<div id="documento_e"></div>
The page that processes the data:
include("banco.php");
if(isset($_POST['documento'])){
$img = $_FILES["arq"]["name"];
$ext = strtolower(strrchr($img, '.'));
$imgn = str_replace($_POST['arqnome'],' ','_').$ext;
$dest = $imgt . '_tmp/' . $imgn;
move_uploaded_file( $_FILES['arq']['tmp_name'], $dest );
pg_query($dbconn, "begin");
$oid = pg_lo_import($dbconn, $imgt . '_tmp/' . $imgn);
$sql = "insert into tabela(arqnome, arq, arqext) values('".$_POST['arqnome']."', '$oid', '$ext'");
$res = pg_query($dbconn,$sql);
pg_query($dbconn, "commit");
unlink($imgt . '_tmp/' . $imgn);
}