I'm doing a system with PHP and I've already been able to put a word image or file directly inside MSSQL , SQLSRV , without needing put them in a folder, but I can not fetch them and display them in the normal format. Does anyone know how I can do this? This data recovery? Bank insertion code:
$dataHex = bin2hex($nome_final);
$imagedata = file_get_contents($nome_final);
$base64 = base64_encode($imagedata);
$sql = "INSERT INTO [RDO].[dbo].[documentosSub] (id_fun, nome_documento, hexa, base64) VALUES (?,?,?,?)";
$params = array($id_fun, $nome_final, $dataHex, $base64);
$stmt = @sqlsrv_query( $conn, $sql, $params);
$pasta = $_UP['pasta'];
$pastaP = explode('/', $pasta);
$pasta = $pastaP[0];
if (move_uploaded_file($_FILES['arquivo']['tmp_name'], $_UP['pasta'] . $nome_final)) {
header("Location: teste.php?pasta=$pasta&id_fun=$id_fun&cc=$cc");
} else {
echo "Não foi possível enviar o arquivo, tente novamente";
}
Display Code:
$sql = "SELECT * FROM [RDO].[dbo].[documentosSub] WHERE id_fun='$id_fun' ";
$stmt = @sqlsrv_query( $conn, $sql);
?>
<table align="center" width="400" border="1">
<tr>
<td align="center"><b>Id</b></td>
<td align="center"><b>Nome</b></td>
<td align="center"><b>Download</b></td>
<td align="center"></td>
</tr>
<?php
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$id_documento = $row['id_documento'];
$nome_documento = $row['nome_documento'];
$hexa = $row['hexa'];
$base = $row['base64'];
$binary_string = pack("H*" , $hexa);
$base64 = base64_decode($base);
$arquivo = $prefixo.'/'.$pasta.'/'.$nome_documento;
$imgP = explode(".", $arquivo);
?>
<tr>
<td align="center"><?php echo $id_documento ?></td>
<td><?php echo $nome_documento ?></td>
<td align="center"><a href="<?php echo $arquivo ?>"><?php echo $nome_documento ?></a></td>
<!--<td><?php echo $base64 ?></td>-->
</tr>
<?php
}
?>
</table>