Good one of the way you can use and this code here it takes the update and saves in the folder of your application and names the photo with the user id after and just recover the photo from the folder and done. Very simple and functional code! anything to say
<?php
session_start();
$PHP_SELF = "";
//Diretório aonde ficará os arquivos
$dir = "./image/users/profile_photo/";
//Extensões permitidas
$ext = array("gif","jpg","png");
//Quant. de campos do tipo FILE
$campos = 6;
//Formulário
echo '<form method="post" action="'.$PHP_SELF.'" enctype="multipart/form-data">
<input type="file" name="file[]">
<br />
<br />
<br />
<input type="submit" name="submit" value=" OK ">
</form>';
//Se for enviado
if (isset($_POST['submit'])) {
//Obtendo info. dos arquivos
$f_name = $_FILES['file']['name'];
$f_tmp = $_FILES['file']['tmp_name'];
$f_type = $_FILES['file']['type'];
//Contar arquivos enviados
$cont=0;
//Repetindo de acordo com a quantidade de campos FILE
for($i=0;$i<$campos;$i++){
//Pegando o nome
$name = $_SESSION['usuarioID'];
//Verificando se o campo contem arquivo
if ( ($name!="") and (is_file($f_tmp[$i])) and (in_array(substr($name, -3),$ext)) ) {
if ($cont==0) {
echo "<b>Arquivo(s) enviados:
</b>";
}
echo $name." - ";
//Movendo arquivo's do upload
$up = move_uploaded_file($f_tmp[$i], $dir.$name);
//Status
if ($up==true):
echo "<i>Enviado!</i>";
$cont++;
else:
echo "<i>Falhou!</i>";
endif;
echo "
";
}
}
echo ($cont!=0) ? "<i>Total de arquivos enviados: </i>".$cont : "Nenhum arquivo foi enviado!";
}
?>
yes and possible to make the img tag receive the EX path:
<div class="perfil">
<img src="/image/users/profile_photo/<?php session_start(); echo $_SESSION['usuarioID']; ?>.jpg">
<img>
</div>
The ideal would be for you to upload the file to a folder and save the name of the file that was uploaded to the database, and then, when displaying the image, select the file name.
– Renato Junior
The problem is I don’t have the images, only the database.
– Rafael Pessoa