I need to ask the user to change the image without changing the database source file, that is, when the user terminates BROWSER after the exchange, he or any other user entering the Site again, you will find the same boot image as it is stored in the DB.
And for this I've been researching but not understanding the reasoning, and I've seen that using $ _SESSION or even $ _COOKIE I could have the desired result, the user swaps the image for another one coming from his own computer, and that image is stored in a SESSION or even as a COOKIE. But I do not know how to create the code to accomplish this task because I did not enter the reasoning of the tutorials that I analyzed, which left me with the following doubts:
What would be the destination folder of the images?
How to keep the image source name when uploading it?
Because the upload I use (posted below) changes the source name of the files, so there are no duplicates of them, using rand () to do so.
How can my friends show me how to build the code with SESSION or COOKIE, based on the example of link ?
Page Code edit_logo-upd.php:
<?php
include 'cabecalho.php';
$logo = $_POST['logo'];
$query = mysql_query("SELECT * FROM pagcabecalho");
$res = mysql_fetch_array($query);
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<div align="center" style="margin: 0 0 0 180px; max-width:1000px;">
<?php
$codigo = $_GET['codigo'];
$query = mysql_query("SELECT * FROM pagcabecalho WHERE codigo = '$codigo'");
$res = mysql_fetch_array($query);
$pasta = '../upload/';
if (isset($_POST['logo'])){
$check = @$_POST['apagar'];
foreach($check as $logo){
$delcheck = mysql_query("UPDATE pagcabecalho SET logo='' WHERE codigo = '$codigo'") or die (mysql_error());
unlink($pasta.'/'.$logo);
if ($delcheck >= '1'){
echo 'Imagem deletada com sucesso!';
}else{
echo 'Erro ao deletar imagem, tente novamente!';
}
}
}
?>
<?php include 'upload_logo.php'; ?>
<form action="" method="POST" enctype="multipart/form-data">
<?php
include '../conexao.php';
$seleciona = "SELECT * FROM pagcabecalho";
$queryum = mysql_query($seleciona);
while ($list = mysql_fetch_array($queryum)){
$logo = $list['logo'];
?>
<input size="1" type="hidden" name="codigo" value="<?php echo $codigo;?>" readonly>
<input type="hidden" type="checkbox" name="apagar[]" value="<?php echo $logo;?>" checked readonly>
<?php
}
?>
<label><h4>Selecione uma nova imagem como Logo:</h4></label><br />
<input type="file" name="logo[]" accept="image/*" ><br />
<input type="submit" name="logo" value="Atualizar">
</form>
</div>
Page Code upload_logo.php:
if(isset($_POST['logo'])){
//INFO IMAGEM
$file = $_FILES['logo'];
$numFile = count(array_filter($file['name']));
//PASTA
$folder = '../upload';
//REQUiSITOS
$permite = array('image/jpeg', 'image/png', 'image/gif');
$maxSize = 1024 * 1024 * 5;
//MENSAGEM
$msg = array();
$errorMsg = array(
1 => 'O arquivo no upload é maior que o Limite de finido em upload_maxsize',
2 => 'O arquivo ultrapassa o limite de tamanho em Max_file_size',
3 => 'O upload do arquivo foi feito parcialmente',
4 => 'Não foi feito o upload do arquivo',
);
if($numFile <= 0)
echo 'Selecione uma Imagem!!';
else{
for($i = 0; $i < $numFile; $i++){
$name = $file['name'][$i];
$type = $file['type'][$i];
$size = $file['size'][$i];
$error = $file['error'][$i];
$tmp = $file['tmp_name'][$i];
$extensao = @end(explode('.', $name));
$novoNome = rand().".$extensao";
if($error != 0)
$msg[] = "<b>$name :</b> ".$errorMsg[$error];
else if (!in_array($type, $permite))
$msg[] = "<b>$name :</b> Erro imagem não suportada!";
else if($size > $maxSize)
$msg[] = "<b>$name :</b> Erro imagem ultrapassa o limite de 5MB!";
else{
if(move_uploaded_file($tmp, $folder."/".$novoNome))
$logo = $_FILES['logo'];
$update = mysql_query("UPDATE pagcabecalho SET logo = '$novoNome' WHERE codigo = '$codigo'");
if($update == ''){
echo "<script language='javascript'>
window.alert('Erro ao atualizar Imagem!!!');
</script>";
}else{
echo "<meta http-equiv='refresh' content='0; URL= ../admin/interna.php'>
<script language='javascript'>
window.alert('Imagem atualizada com sucesso!');
</script>";
}}}}}
?>
From now on my thanks for the attention to my doubt, and hugs to all.