Jump to content

[Resolvido] Problema base64_encode upload de imagens na base dados


Recommended Posts

Posted

Olá gostaria de ajuda neste problema. Estou a fazer upload de uma foto para mysql a partir de php e mais tarde a fazer load da mesma em outro php. Mas dá erro

Status Code:

Citação

414 Request-URI Too Large devido ao base64_encode que uso no file.

O código funciona todo mas dá este erro. Alguém têm uma solução para poder fazer upload e load do file que está na base de dados.

Código html:




  <form name="uploadFile" id="uploadFile" method="POST" action="alimentacao/FileUploadServlet.php" enctype="multipart/form-data"  target="upload_target" >
<table border="0">
		<tr>
<td align="right"><span for="name" class="legendaForm"></span></td>
			<td colspan="3"><div id="not"></div></td>
</tr>
<tr>


<td align="right"><span for="name" class="legendaForm">* Nome:</span></td>
			<td colspan="3"> <div id="name"></div><input class="vazioForm" type="text" id="nome" name="nome" size="43" /></td>
</tr>

<tr>


<td align="right"><span for="imagem" class="legendaForm"></span></td>
			<td colspan="3"><div id="infoErro"></div></td>
	 </tr>


	<tr>
<td align="right"><span for="imagem" class="legendaForm"> Imagem:</span></td>
			<td colspan="3"><input class="vazioForm" type="file" id="file" name="file" size="43" /></td>
<iframe style="display:none;" id="upload_target" name="upload_target"  height="1000px" width="1000px" src=""></iframe>
	 </tr>

<tr>
<td  align="right"><span for="descricao" class="legendaForm"> Descrição:</span></td>
			<td colspan="3"><textarea class="vazioForm" id="descricao" rows="3" cols="30" name="descricao" ></textarea></td>
</tr>
<tr>
<td align="right"><span for="gramas" class="legendaForm">* Gramas:</span></td>
<td> <input  class="vazioForm" type="text" name="gramas"  id="gramas" size="5" /></td>

<td align="right"><span for="calorias" class="legendaForm">* Calorias:</span></td>
<td> <input  class="vazioForm" type="text" name="calorias"  id="calorias" size="5" /></td>
</tr>

<tr>
<td align="right"><span for="agua" class="legendaForm">Água:</span></td>
<td> <input class="vazioForm" type="text" name="agua"  id="agua" size="5" /></td>
			<td align="right"><span for="proteinas" class="legendaForm">Proteinas:</span></td>
<td> <input  class="vazioForm" type="text" name="proteinas"  id="proteinas" size="5" /></td>
</tr>

<tr>
<td align="right"><span for="gordura" class="legendaForm">Lípidos:</span></td>
<td> <input  class="vazioForm" type="text" name="gordura"  id="gordura" size="5" /></td>
			<td align="right"><span for="Hcarbono" class="legendaForm">H.Carbono:</span></td>
<td> <input  class="vazioForm" type="text" name="Hcarbono"  id="Hcarbono" size="5" /></td>
</tr>

<tr>
<td align="right"><span for="celulose" class="legendaForm">Sódio:</span></td>
<td> <input  class="vazioForm" type="text" name="sodio"  id="sodio"  size="5"/></td>
			<td align="right"><span for="calcio" class="legendaForm">Calcio:</span></td>
<td> <input  class="vazioForm" type="text" name="calcio"  id="calcio"  size="5"/></td>
</tr>

<tr>
<td align="right"><span for="fosforo" class="legendaForm">Fosforo:</span></td>
<td> <input  class="vazioForm" type="text" name="fosforo"  id="fosforo"  size="5"/></td>
			<td align="right"><span for="ferro" class="legendaForm">Ferro:</span></td>
<td> <input  class="vazioForm" type="text" name="ferro" id="ferro"  size="5"/></td>
</tr>

  <td>  <input class="botaoForm" id="botao" type="submit" value="Guardar" /></td>

</form>

 

Código php: neste momento só estou a tentar inserir foto



<?php


include '../../Classes/Geral.class.php';
include '../../Classes/Alimentacao.class.php';

  $alim = new Alimentacao();


if (   ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")){
 $image = base64_encode(fread(fopen($_FILES["file"]["tmp_name"], "r"), filesize($_FILES["file"]["tmp_name"])));
  }


$alim->InsereFoto($image);

?>

 

Código php que chama a file do fim de a ir buscar há base dados



<?PHP

if(isset($fotoAlim)){



$image = base64_encode($fotoAlim);


	 ?>



   <img src="data:image/png;base64,<?php echo $image; ?>" />

 <?php
 }
 ?>

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.