Ir para conteúdo
Fórum Script Brasil
  • 0

DÚvida_galeria_php


bandit23

Pergunta

Estou seguindo os passos de um forum que achei sobre galeria de imagens: http://forum.wmonline.com.br/index.php?sho...=34335&st=0

Só que estou com dúvidas em algumas partes.

Eu criei a tabela:

-- phpMyAdmin SQL Dump
-- version 2.9.1-rc1
-- http://www.phpmyadmin.net
-- 
-- Servidor: localhost
-- Tempo de Geração: Nov 22, 2006 as 05:53 PM
-- Versão do Servidor: 5.0.24
-- Versão do PHP: 5.1.6
-- 
-- Banco de Dados: `album`
-- 

-- --------------------------------------------------------

-- 
-- Estrutura da tabela `galeria`
-- 

CREATE TABLE `galeria` (
  `id` int(3) unsigned zerofill NOT NULL auto_increment,
  `nome` varchar(20) NOT NULL,
  `data` date NOT NULL,
  `local` varchar(255) NOT NULL,
  `qts_fotos` char(3) NOT NULL,
  `pasta` varchar(255) NOT NULL,
  `foto01` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
pagina do novo_evento.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Novo Evento</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#000000" link="#FF0000" vlink="#CCCCCC" alink="#CCCCCC">
<div align="center">
<table width="400" border="1" bordercolor="#666666">
<tr>
<td width="464">
<p align="center"><font color="#000000" size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#FFFFFF">Cadastro de um novo Evento</font></strong></font></p>
<form name="form1" method="post" action="envia_evento.php">
<table width="334" border="1" bordercolor="#666666">
<tr>
<td width="129"><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Nome do Evento:</font></td>
<td width="195"><input type="text" name="nome" size="30" maxlength="50"></td>
</tr>
<td width="129"><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Data do Evento:</font></td>
<td width="195">
<input type="text" name="data" size="10" maxlength="10">
</td>
</tr>
</table>
<p align="center"><input type="submit" name="Submit" value="Enviar"></p></form>
</td>
</tr>
</table>
</div>
<div align="center"></div>
<div align="center"></div>
<p>&nbsp;</p>

</body>
</html>
envia_evento.php
<?php
    include "conecta_mysql.inc";
     $nome = $_POST["nome"];
     $data = $_POST["data"];
    $sql = mysql_query ("INSERT INTO evento(nome, data) VALUES('$nome', NOW())")
    or die("Erro no SQL: ".mysql_error()); /*Insere um evento no banco de dados*/
    echo "Evento cadastrado com sucesso!!<br><META HTTP-EQUIV='refresh' CONTENT='0; URL=inc_foto.php'>";
    /* fecha erros = 0 */
?>
O erro começa agora agora: cadastrar.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



<?php
    include "conecta_mysql.inc"; 
?>

<script language="javascript">
function validate (theForm)
{
    if (theForm.nome.value == "")
    {
        alert ("Digite o nome do Link");
        theForm.nome.focus();
        return (false);
    }
return (true);
}
</script>
<style fprolloverstyle>A:hover
    {
        color:"#666666"; text-decoration:underline
    }
body {
    background-color: #33CC99;
}
</style>
</head>
<body link="#000000" vlink="#000000" alink="#000000" leftmargin="0" topmargin="0">
<form action="cadastra_db.php" method="post" onSubmit="return validate(this);" enctype="multipart/form-data">
<table width="400" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td align="center" height="30"><font size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>Cadastrar Galeria:</strong></font></td>
    </tr>
</table>

<table width="682" align="center" cellpadding="3" cellspacing="0" style="border: 1px solid #000000">
    <tr>
        <td width="674" bgcolor="#33CC99"><table border="0" cellpadding="1" cellspacing="0">
            <tr>
                <td width="158" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Nome:</strong></font></td>
                <td width="280"><input type="text" name="nome" style="width:280" maxlength="255"></td>
              </tr>
        </table>
       </td>
    </tr>
    <tr>
        <td bgcolor="#33CC99"><table width="445" border="0" cellpadding="1" cellspacing="0">
            <tr>
                <td width="159" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Data:</strong></font></td>
                <td width="282" valign="top"><input type="text" name="data" style="width:100" maxlength="10">
                <em><font size="2" face="Verdana, Arial, Helvetica, sans-serif">ex: 10/10/2003</font></em></td>
            </tr>
        </table>
        </td>
    </tr>    
    <tr>
        <td bgcolor="#33CC99"><table width="445" border="0" cellpadding="1" cellspacing="0">
            <tr>
                <td width="159" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Local:</strong></font></td>
                <td width="282"> <input type="text" name="local" style="width:280" maxlength="255"></td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
        <td bgcolor="#33CC99"><table width="445" border="0" cellpadding="1" cellspacing="0">
            <tr>
                <td width="159" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Pasta de Destino:</strong></font></td>
                <td width="282"> <input type="text" name="nomepasta" style="width:280"></td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
        <td bgcolor="#33CC99"><table width="674" border="0" cellpadding="1" cellspacing="0">
            <tr>
                <td width="162" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Quantidade de Fotos:</strong></font></td>
                <td width="122"> <input type="text" name="qts_fotos" size="10" style="width:30"></td>
                <td width="152" align="left"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Foto de Destaque:</strong></font></td>
                <td width="230"><input type="file" name="foto01" style="width:160"></td>
            </tr>
        </table>
        </td>
    </tr>
</table>
    <table width="400" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td height="35" colspan="4" align="center">
            <input type="submit" value="Cadastrar" name="submit">
            <input type="reset" value="Limpar">
            </td>
        </tr>
    </table>
</form>
</body>
</html>
Ex: coloco o nome da foto como teste, coloco a data, digito o local do evento, coloco a pasta de destino como C:\root\album\img\galeria pois criei com o botão direito, coloco quantidade de foto como 1 e em procurar seleciono a foto. até aí tudo bem. na hora que clico em cadastrar vem o erro em cadastrar_db.php Erros: Notice: Undefined index: foto01_nome in C:\root\album\cadastra_db.php on line 16 Warning: mkdir() [function.mkdir]: Invalid argument in C:\root\album\cadastra_db.php on line 20 O código de cadastrar_db.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#33CC99">
<?php
include "conecta_mysql.inc";
$nome = $_POST["nome"];
$data = $_POST["data"];
$local = $_POST["local"];
$qts_fotos = $_POST["qts_fotos"];
$nomepasta = $_POST["nomepasta"];
$foto01_nome = $_POST["foto01_nome"];
//criação da pasta
if ($nomepasta != "")
{
    $pasta = mkdir("../img/galeria/$nomepasta");
}
//fim da criação da pasta

//função para eviar a foto
if ($pasta == "$nomepasta" AND $foto01 != "")
{
    if (copy($foto01,"../img/galeria/$nomepasta".$foto01_nome))
    {
        echo "<br> <div align='center'><font face='verdana' size='2'><b>Foto Enviada com sucesso!</b></font></div><br>";
    }
    else
    {
        echo "<br><div align='center'><font face='verdana' size='2'><b>Erro no Enviar a Foto!</b></font></div><br>";
    }
}
//termina a função para enviar a foto

if ($pasta == "$nomepasta" AND $foto01 != "")
{
    $sql = "insert INTO galeria (nome, data, local, qts_fotos, nomepasta, foto01_nome) VALUES ('$nome', NOW(), '$local', '$qts_fotos', '$nomepasta', '$foto01_nome')";
    $sql = mysql_query($sql);
?>
<meta http-equiv="refresh" content="2" URL=../img/enviar_fotos.php?nomepasta=<?php echo "$nomepasta";?>">
<br>
<center>
<h3><b><font face="Tahoma">Galeria cadastrada com Sucesso!</font></b></h3>
</center>
<?php
}
?>
</body>
</html>
Em criar_dir.php o erro é o seguinte. digito o nome da pagina sendo como gale e quando clico em criar, é a criada a pasta galeria sem eu digitar o nome completo. E em seguida sou redirecionado para a página criar_pasta.php onde me aparece alguns erros: Ex: Notice: Undefined variable: nomepasta in C:\root\album\criar_pasta.php on line 14 A pasta Notice: Undefined variable: nomepasta in C:\root\album\criar_pasta.php on line 19 foi criada com sucesso! O código de criar_dir.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#33CC99">
<?php 
    include "conecta_mysql.inc";
    include "menu.php";
?>
<br>
<center>
    <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>CRIAR PASTA</strong></font></center><br>
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td align="center">
                <form method="post" name="form1" action="criar_pasta.php">
                    <input type="text" name="nomepasta" style="width:150; height:20; border:1px solid" maxlength="25">
                    <input type="submit" name="Submit" value="Criar" style="width:50; height:20; border:1px solid">
                </form>
            </td>
        </tr>
    </table>
</body>
</html>
O código de criar_pasta.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#33CC99">
<?php
    include "conecta_mysql.inc";
    include "menu.php";
?>
<?php
    mkdir ("galeria/$nomepasta", 0777);
?>
<meta http-equiv="refresh" content="2;URL=listar_arquivos.php">
<center>
<br><br><br>
<font size="5" face="Verdana, Arial, Helvetica, sans-serif">A pasta<strong><?php echo "$nomepasta"; ?></strong>foi criada com sucesso!</font></center>
</body>
</html>

Desde já quem puder me ajudar, agradeço. Obrigado.

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

No "cadastrar_db.php" o problema é que você não está enviando nenhuma variável com o nome "foto01_nome", desta forma, a instrução "$foto01_nome = $_POST["foto01_nome"];" retorna um erro. Já no caso do "criar_pasta.php", você não está recuperando o valor da variável "nomepasta". coloque um "$nomepasta=$_POST("nomepasta");" no código antes do mkdir.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,8k
×
×
  • Criar Novo...