How can I send 5 images to the destination folder (upload), and at the same time already save the names (img.jpeg) of these images in the database table, using PHP and MySql?
I tried using the same reasoning as I use to send a single file, and I tried to adapt the upload files, upload_serv.php and form, thus:
Form:
<div align="center" style=" padding:2px; float:left; width:290px; height:auto;">
<?php
include '../conexao.php';
$codigo = $_GET['codigo'];
$query = mysql_query("SELECT * FROM serv WHERE codigo = '$codigo'");
$res = mysql_fetch_array($query);
$pasta = '../img_serv/';
if (isset($_POST['upload'])){
$check = @$_POST['apagar'];
foreach($check as $img01){
$delcheck = mysql_query("UPDATE serv SET img01='' WHERE codigo = '$codigo'") or die (mysql_error());
unlink($pasta.'/'.$img01);
foreach($check as $img02){
$delcheck = mysql_query("UPDATE serv SET img02='' WHERE codigo = '$codigo'") or die (mysql_error());
unlink($pasta.'/'.$img02);
foreach($check as $img03){
$delcheck = mysql_query("UPDATE serv SET img03='' WHERE codigo = '$codigo'") or die (mysql_error());
unlink($pasta.'/'.$img03);
foreach($check as $img04){
$delcheck = mysql_query("UPDATE serv SET img04='' WHERE codigo = '$codigo'") or die (mysql_error());
unlink($pasta.'/'.$img04);
foreach($check as $img05){
$delcheck = mysql_query("UPDATE serv SET img05='' WHERE codigo = '$codigo'") or die (mysql_error());
unlink($pasta.'/'.$img05);
if ($delcheck >= '1'){
echo 'Imagem deletada com sucesso!';
}else{
echo 'Erro ao deletar imagem, tente novamente!';
}}}}}}}
?>
<?php include 'upload_serv.php'; ?>
<form action="" method="post" enctype="multipart/form-data">
<?php
include '../conexao.php';
$seleciona = "SELECT * FROM serv";
$queryum = mysql_query($seleciona);
while ($list = mysql_fetch_array($queryum)){
$img01 = $_FILES['img01'];
$img02 = $_FILES['img02'];
$img03 = $_FILES['img03'];
$img04 = $_FILES['img04'];
$img05 = $_FILES['img05'];
}
?>
<input type="hidden" type="checkbox" name="apagar[]" value="<?php echo $img01;?>" checked readonly>
<input type="hidden" type="checkbox" name="apagar[]" value="<?php echo $img02;?>" checked readonly>
<input type="hidden" type="checkbox" name="apagar[]" value="<?php echo $img03;?>" checked readonly>
<input type="hidden" type="checkbox" name="apagar[]" value="<?php echo $img04;?>" checked readonly>
<input type="hidden" type="checkbox" name="apagar[]" value="<?php echo $img05;?>" checked readonly>
<label>Selecione Imagem(ns)</label><br />
<input type="file" name="img01[]" multiple="multiple" accept="image/*" ><br /><br />
<input type="file" name="img02[]" multiple="multiple" accept="image/*" ><br /><br />
<input type="file" name="img03[]" multiple="multiple" accept="image/*" ><br /><br />
<input type="file" name="img04[]" multiple="multiple" accept="image/*" ><br /><br />
<input type="file" name="img05[]" multiple="multiple" accept="image/*" ><br /><br />
<input type="submit" name="upload" value="Upload">
</form>
</div>
The Upload file:
<?php
if(isset($_POST['enter'])){
//INFO IMAGEM
$file = $_FILES['img01'];
$numFile = count(array_filter($file['name']));
$file = $_FILES['img02'];
$numFile = count(array_filter($file['name']));
$file = $_FILES['img03'];
$numFile = count(array_filter($file['name']));
$file = $_FILES['img04'];
$numFile = count(array_filter($file['name']));
$file = $_FILES['img05'];
$numFile = count(array_filter($file['name']));
//PASTA
$folder = '../img_serv';
//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))
$img01 = $_FILES['img01'];
$img02 = $_FILES['img02'];
$img03 = $_FILES['img03'];
$img04 = $_FILES['img04'];
$img05 = $_FILES['img05'];
$update = mysql_query("UPDATE serv SET img01 = '$novoNome', img02 = '$novoNome', img03 = '$novoNome', img04 = '$novoNome', img05 = '$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= serv_edit.php'>
<script language='javascript'>
window.alert('Imagem atualizada com sucesso!');
</script>";
$msg[] = "<b>$name :</b> Upload realizado com sucesso!";
else{
$msg[] = "<b>$name :</b> Ocarreu um erro com o Upload!";
}}}}}
?>
Well this is what I have, if friends can help me to register the image files in the database and the destination folder simultaneously, I will be grateful. Hugs to all, and thanks for the attention.