3
You can send 5 images to the target folder (upload), and at the same time record the names (img.jpeg) of these images in the Database table, using PHP and Mysql?
Because 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 the form, so this is how it is:
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 file Upload:
<?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 that’s what I have, if friends can help me to register the image files in the database and in the destination folder simultaneously, I’ll be grateful. Hugs to all, and thank you for your attention.
Take a look at this post, has to send 1 and multiple images as needed http://answall.com/questions/92974/upload-image/ does not have the sending snippet for the bd but is easy to implement.
– Thyago ThySofT