Cadastrando não só 1, porém mais imagens, se necessário.
Olá pessoal.
Estou usando um código, há tempo, e agora preciso de uma implementação nesse código, inserindo mais de um campo para inserção de mais imagens, e não apenas 1 como é o original. Acontece, que estou tentando duplicar as variáveis e seus comandos, porém não estou obtendo sucesso.
Envio o código para melhor apreciação e visualização de vcs, para que possam me ajudar, por gentileza.
funcao_insert.php
<?php
//This is the directory where images will be saved
$target = "arquivos_upload/";
$target = $target . basename( $_FILES['upload']['name']);
//This gets all the other information from the form
$data = date("Y/m/d");
$hora = strftime("%H:%M:%S");
$modelo =$_POST['modelo'];
$medidas =$_POST['medidas'];
$furos =$_POST['furos'];
$peso =$_POST['peso'];
$pecas =$_POST['pecas'];
$name =$_POST['name'];
$pic =$_FILES['upload'];
// Connects to your Database
$con = mysql_connect("localhost", "bd", "usuario") or die(mysql_error()) ;
//mysql_select_db("upload") or die(mysql_error()) ;
mysql_select_db("bd") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO tb_produtos VALUES (NULL, '$data', '$hora', '$modelo', '$medidas', '$furos', '$peso', '$pecas', '$name', '')");
//Writes the photo to the server
$ultReg = mysql_insert_id($con);
$ext = substr($pic[name], -3);
$tmpName = $pic['tmp_name'];
$nome = $ultReg . "_" . ($i+1) . "." . $ext;
if (move_uploaded_file($tmpName, $target)){
$caminho = "arquivos_upload/";
$novo_nome = rename("$caminho$pic[name]","$caminho$nome");
$uSql = mysql_query("UPDATE tb_produtos SET upload = '" . $nome . "' WHERE id = " . $ultReg);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxx</title>
<link rel="stylesheet" type="text/css" href="../../estilo.css">
</head>
<body>
<table width="662" border="0" align="center" cellpadding="0" cellspacing="10">
<tr><td><a href="index.php"><b>Lista de Cadastros</b></a>
<fieldset>
<legend><span class="titulo_form">SITUAÇÃO DO CADASTRO - Qualidade</span></legend>
<p><span class="fonte_preto_negrito"><center>O cadastro foi INSERIDO com sucesso!</center></span></p>
</fieldset>
</table>
</body>
</html>
<?php
}else {
//Gives and error if its not
echo "Desculpe, ocorreu algum problema ao enviar arquivo.";
}
?>
cadastro_inserir.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>xxx</title>
<link rel="stylesheet" type="text/css" href="../../estilo.css">
<script src="../nicEdit.js" type="text/javascript"></script>
</head>
<body>
<form enctype="multipart/form-data" action="funcao_insert.php" method="post" name="form1" id="form1">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="10">
<tr><td><a href="javascript:history.back()">Voltar</a>
<fieldset>
<legend><span class="titulo_form">INSERIR CADASTRO</span></legend>
<table width="100%" border="0" cellspacing="10" cellpadding="0">
<tr>
<td width="100" valign="top"><span class="titulo">MODELO:</span></td>
<td><input name="modelo" type="text" class="texto" id="modelo" size="70"/></td>
</tr>
<tr><td valign="top"><span class="titulo">MEDIDAS (cm):</span></td>
<td><input name="medidas" type="text" class="texto" id="medidas" size="70"/></td>
</tr>
<tr><td valign="top"><span class="titulo">FUROS:</span></td>
<td><input name="furos" type="text" class="texto" id="furos" size="70"/></td>
</tr>
<tr><td valign="top"><span class="titulo">PESO (kg):</span></td>
<td><input name="peso" type="text" class="texto" id="peso" size="70"/></td>
</tr>
<tr><td valign="top"><span class="titulo">PEÇAS/m<sup>2</sup>:</span></td>
<td><input name="pecas" type="text" class="texto" id="pecas" size="70"/></td>
</tr>
<tr>
<td valign="top"><span class="titulo">ARQUIVO:</span></td>
<td valign="top"><input type="file" id="upload" name="upload"/></td>
</tr>
<tr><td colspan="2" align="right"><input name="enviar" type="submit" class="titulo" id="enviar" value="Enviar"/></td></tr>
</table>
</fieldset>
</td></tr></table>
<input type="hidden" value="form1"/>
</form>
</body>
</html>
Aguardo contato e retorno de vocês!!!
Preciso muito dessa ajuda e sei que paralelamente poderá auxiliar muito aqueles que também encontram-se no mesmo dilema.
Aline R.
Discussão (5)
Carregando comentários...