0
I’m making a system with PHP and I have already managed to place an image or word file, directly, inside the MSSQL, SQLSRV, without having to put them in a folder, but I can’t find them and display them in normal format. Does anyone know how I can do this? This data recovery thing? Insertion code in the bank:
$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";
}
Code for display:
$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>
The problem is that I am not using version 5.4 of php that supports hex2bin and the program I am running here is Vertrigo, similar to XAMPP, WAMPP, but there is no upgrade to php 5.4. I have a mega problem in hand. I would like to convert the image or doc to another format for the bank and then undo the conversion?
– GustavoSevero
@Gustavosevero Edit the question stating this reason not to use
hex2bin
, or your question will be closed as duplicate.– Caffé
which version of php
– Otto
Sorry Caffé, but in what way you want me to edit the question?
– GustavoSevero
Hi Otto, it’s version 5.3
– GustavoSevero
it is interesting to always put as much information as possible so that we can help....
– Otto
Not to miss the joke .... Gustavo I think you are too Severo
– Otto
I was able to convert the image, before saving in the bank, as Base64, but also I am not able to recover it.
– GustavoSevero
Got how ? tried with the answer I sent ?
– Otto
Simply, doing this: $imagedata = file_get_contents($endname); $Base64 = base64_encode($imagedata);
– GustavoSevero
then Voce threw her into the bank with Base64 .... makes the base64_decode
– Otto
what you have in the $Base64 ?
– Otto
You posted the code you are trying to use. Cool. But I think it is now unclear what problem you are facing.
– Caffé
Caffé, the problem of before, I can not make the image appear on the screen, or a link to the image.
– GustavoSevero