Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Seguinte, eu tentei adaptar o código do Fábio mas a única coisa que não acontece eh a inclusão do caminho da foto no BD. Seguem os códigos:
formulario.php
<form action="envia_produto.php" method="post" enctype="multipart/form-data"> <table width="760" cellpadding="0" cellspacing="0" style="border:1px solid #ccc; padding:10px 10px 10px 10px;"> <tr> <td width="400" class="formtitulo" colspan="2">Incluir Produto</td> </tr> <tr> <td width="300" class="formitem"><strong>Categoria:</strong><br /> Selecione a categoria do produto</td> <td width="300"><select name="cod_cat" id="cod_cat" class="formselect"> <?php do { ?> <option value="<?php echo $result_cat['cd_categoria']?>"><?php echo $result_cat['nome_categoria']?></option> <?php } while ($result_cat = mysql_fetch_assoc($query_cat)); $rows = mysql_num_rows($query_cat); if($rows > 0) { mysql_data_seek($query_cat, 0); $result_cat = mysql_fetch_assoc($query_cat); } ?> </select></td> </tr> <tr> <td width="300" class="formitem"><strong>Nome do Produto:</strong><br /> Nome do produto</td> <td width="300"><input name="produto" type="text" class="formimport" style="width:200px;" /></td> </tr> <tr> <td width="300" class="formitem"><strong>Descrição do Produto:</strong><br /> Descrição do produto</td> <td width="300"><textarea name="descricao" style="width:200px;" rows="5" class="formimport" /></textarea></td> </tr> <tr> <td width="300" class="formitem"><strong>Valor do Produto:</strong><br /> Utilize apenas números</td> <td width="300">R$ <input name="valor" type="text" class="formimport" style="width:40px;" /> ,00</td> </tr> <tr> <td width="300" class="formitem"><strong>Foto do Produto:</strong><br /> Envie uma imagem do produto no formato jpg ou jpeg</td> <td width="300"><input type="file" name="arquivo" /></td> </tr> <tr> <td width="300" class="formitem"><strong>Destacar o Produto?</strong><br /> Marcando o produto como destaque, ele aparecerá na capa do site</td> <td width="300"><select name="destaque" class="formselect"> <option value="nao" selected>Não</option> <option value="sim">Sim</option> </select></td> </tr> <tr> <td width="300" class="formitem"><strong>Garantia do Produto:</strong><br /> Garantia do produto em meses</td> <td width="300"><input name="garantia" type="text" class="formimport" style="width:20px;" /> Meses</td> </tr> <tr> <td width="300" colspan="2" class="formsend"><input type="submit" name="incluir" value="Incluir" /></td> </tr> </table> </form>
envia_produto.php
<?include('ver_session.php');require_once('../Connections/conn.php');require_once('class_upload.php');$upload = new Upload();$upload->Envia_Arquivo();$cod_cat = $HTTP_POST_VARS['cod_cat'];$nome = $HTTP_POST_VARS['produto'];$descricao = nl2br($HTTP_POST_VARS['descricao']);$garantia = $HTTP_POST_VARS['garantia'];$valor = $HTTP_POST_VARS['valor'];$destaque = $HTTP_POST_VARS['destaque'];$insere = "INSERT INTO produtos (cd_produto, cd_categoria, nome, descricao, garantia, valor, imagem, destaque) VALUES (NULL, '$cod_cat', '$nome', '$descricao', '$garantia', '$valor', '$nome_thumb', '$destaque')";mysql_query($insere, $conn) or die (mysql_error());?>
class_upload.php
<?set_time_limit(0);include "funcoes.php";class Upload{ var $arquivo = ""; var $erro = array ( "0" => "Upload realizado com sucesso!", "1" => "O arquivo é maior que o permitido pelo Servidor", "2" => "O arquivo é maior que o permitido pelo formulario", "3" => "O upload do arquivo foi feito parcialmente", "4" => "Não foi feito o upload do arquivo" ); function Verifica_Upload() { $this->arquivo = isset($_FILES['arquivo']) ? $_FILES['arquivo'] : FALSE; if(!is_uploaded_file($this->arquivo['tmp_name'])) { return false; } $get = getimagesize($this->arquivo['tmp_name']); if($get["mime"] != "image/jpeg") { echo "<span style=\"color: white; border: solid 1px; background: red;\">Esse foto nao é uma imagem valida</span>"; exit; } return true; } function Envia_Arquivo() { if($this->Verifica_Upload()) { $this->gera_fotos(); return true; } else { echo "<span style=\"color: white; border: solid 1px; background: red;\">".$this->erro[$this->arquivo['error']]."</span>"; } } function gera_fotos() { $diretorio = "../produtos/"; if(!file_exists($diretorio)) { mkdir($diretorio); } $nome_foto = "imagem_".time().".jpg"; $nome_thumb = "thumb_".time().".jpg"; // ISSO Q EU QUERIA INCLUIR NO BD //determino uma resolução maxima e se a imagem for maior ela sera reduzida reduz_imagem($this->arquivo['tmp_name'], 400, 300, $diretorio.$nome_foto); //passo o tamanho da thumbnail reduz_imagem($this->arquivo['tmp_name'], 120, 90, $diretorio.$nome_thumb); echo "<span style=\"color: white; border: solid 1px; background: blue;\">".$this->erro[$this->arquivo['error']]."</span>"; } }?>
Alguém pode me dizer o motivo de n estar incluindo o caminho no bd? Simplesmente fica vazio o campo da tabela, o resto dá td certo.
Eu queria que a parte "$nome_thumb" fosse inclusa no bd.
Vlw
Carregando comentários...