Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Marcelo Della Mea

Colocando documento em anexo...

Recommended Posts

alterei o arquivo que tem o formulario e salva.. e testei.. funcionou..

 

teste ai..

 

antes crie a pasta "anexos"

 

<h2>Cadastro de nova notícia</h2><form action="" method="POST" enctype="multipart/form-data"><?if (!$_POST) {?><input type="hidden" name="opcao" value="cadNoticia" /><input type="hidden" name="acao" value="cadastrar" />Título<br /><input type="text" name="titulo" size="60" maxlength="60" /><br />Fonte<br /><input type="text" name="fonte" size="25" maxlength="21" /><br />Texto:<br /><textarea name="texto" class="tarea"></textarea><br /><br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">buscar arquivo: <input type="file" name="arquivo"><br /><br />Nome do arquivo anexado : <input type="text" name="nome_anexo" size="25" maxlength="21" /> EX: Projeto.doc<br /><br /><br /><input type="submit" value="Cadastrar Dados" class="sub"></form><?}else{$nome_anexo   = $_FILES["arquivo"]["name"];	// pega o nome original do arquivo$arquivo_id   = md5(uniqid(rand(), true));   // gera um id unico$arquivo_ext  = strrchr($_FILES['arquivo']['name'], '.');  // pega a extenção do arquivo$arquivo_nome = $arquivo_id.$arquivo_ext;  // gera o nome do arquivo com id unico$titulo	   = $_POST['titulo'];$texto		= $_POST['texto'];$fonte		= $_POST['fonte'];$nome_anexo   = $_POST['nome_anexo'];if (move_uploaded_file($_FILES["arquivo"]["tmp_name"],"anexos/".$arquivo_nome)) {	  $sql = "insert into noticias values (null, '$titulo', '$texto', current_date(), current_time(), '$fonte', '$arquivo_nome', '$nome_anexo')";	  conecta();	  mysql_query($sql) or die ("ERRO : ".mysql_error());	  desconecta();	  print "<center>Registro Inserido com Sucesso</center>";} else {	  print "<center><font color='#FF0000'><b>O arquivo não pode ser carregado.</b></font></center>";}}?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Warning: Unable to create 'anexos/c3cc2d6174223a93d930bb23f29c036f.txt': No such file or directory in c:\apache\htdocs\phpmyadmin\intranet\admin\include\cadNoticia.php on line 45Warning: Unable to move 'C:\WINNT\phpF.tmp' to 'anexos/c3cc2d6174223a93d930bb23f29c036f.txt' in c:\apache\htdocs\phpmyadmin\intranet\admin\include\cadNoticia.php on line 45O arquivo não pode ser carregado.a estrutura de diretórios aqui esta assim dentro de intranet ficam os dir admin - anexos - includes - img

Compartilhar este post


Link para o post
Compartilhar em outros sites

substitua a linhaif (move_uploaded_file($_FILES["arquivo"]["tmp_name"],"anexos/".$arquivo_nome)) {paraif (move_uploaded_file($_FILES["arquivo"]["tmp_name"],"../anexos/".$arquivo_nome)) {

Compartilhar este post


Link para o post
Compartilhar em outros sites

em qual parte do código tu define daonde o arquivo vai buscar depois ?

 

pq tipo agora ele ta gravando beleza.. copia pra pasta e tals.. mas quando tu passa o mouse em cima do link do anexo.. ele deveria buscar..em http://localhost/phpmyadmin/intranet/anexos/arquivo.txt

e esta buscando assim

http://localhost/phpmyadmin/intranet/arquivo.txt

 

onde tu altera isso ou onde isso eh definido ..

Compartilhar este post


Link para o post
Compartilhar em outros sites

no arquivo que lista a noticia.. na linha<a href='eventos/$file' target='blank'><b> $nome_anexo </b> </a> <br />";altere para <a href='anexos/$file' target='blank'><b> $nome_anexo </b> </a> <br />";ou<a href='../anexos/$file' target='blank'><b> $nome_anexo </b> </a> <br />";

Compartilhar este post


Link para o post
Compartilhar em outros sites

***Resolvidofechou cara.. agora deu beleza.. vou postar os dois arquivos aqui.. valeu pela ajudaCadastrando nova noticia no banco / com upload de arquivo<h2>Cadastro de nova notícia</h2><form action="" method="POST" enctype="multipart/form-data"><?if (!$_POST) {?><input type="hidden" name="opcao" value="cadNoticia" /><input type="hidden" name="acao" value="cadastrar" />Título<br /><input type="text" name="titulo" size="60" maxlength="60" /><br />Fonte<br /><input type="text" name="fonte" size="25" maxlength="21" /><br />Texto:<br /><textarea name="texto" class="tarea"></textarea><br /><br /><input type="hidden" name="MAX_FILE_SIZE" value="1000000">buscar arquivo: <input type="file" name="arquivo"><br /><br />Nome do arquivo anexado : <input type="text" name="nome_anexo" size="25" maxlength="21" /> EX: Projeto.doc<br /><br /><br /><input type="submit" value="Cadastrar Dados" class="sub"></form><?}else{$nome_anexo = $_FILES["arquivo"]["name"]; // pega o nome original do arquivo$arquivo_id = md5(uniqid(rand(), true)); // gera um id unico$arquivo_ext = strrchr($_FILES['arquivo']['name'], '.'); // pega a extenção do arquivo$arquivo_nome = $arquivo_id.$arquivo_ext; // gera o nome do arquivo com id unico$titulo = $_POST['titulo'];$texto = $_POST['texto'];$fonte = $_POST['fonte'];$nome_anexo = $_POST['nome_anexo'];if (move_uploaded_file($_FILES["arquivo"]["tmp_name"],"../anexos/".$arquivo_nome)) { $sql = "insert into noticias values (null, '$titulo', '$texto', current_date(), current_time(), '$fonte', '$arquivo_nome', '$nome_anexo')"; conecta(); mysql_query($sql) or die ("ERRO : ".mysql_error()); desconecta(); print "<center>Registro Inserido com Sucesso</center>";} else { print "<center><font color='#FF0000'><b>O arquivo não pode ser carregado.</b></font></center>";}}?>Abrindo a mensagem <?php$_GET["$id_noticia"];$sql = "select id_noticia, titulo, texto, date_format(data, '%d/%m/%Y') data, hora, fonte, file, nome_anexo from noticias where id_noticia = $id_noticia";$query = consultaSql($sql) or die (sql_error());if (temRegistro($query) == true) // se tiver registros na tabela{ while ($row = mysql_fetch_array($query)) { $id_noticia =$row["id_noticia"]; $titulo = $row["titulo"]; $texto = $row["texto"]; $data = $row["data"]; $hora = $row["hora"]; $fonte = $row["fonte"]; $file = $row["file"]; $nome_anexo = $row["nome_anexo"]; echo "<font color='#e1a900'> <b> - - : $titulo</b> </font> <div align='right'> Notícia Inserida dia <font color='#e1a900'> $data</font> ás <font color='#e1a900'> $hora <br></font> </div><br /> "; echo "<div align='justify'> $texto <br></div><br />"; echo "<font color='#e1a900'><b>Fonte:</b></font><em> $fonte </em> <br /> <br />"; echo "<b>Anexo<img src='img/anexo.gif' />:</b> <a href='anexos/$file' target='blank'><b> $nome_anexo </b> </a> <br />"; echo ".............................................................................................................<br />"; }}?> <div align="right"><ul id="menu_3"><li><a href="?view=listaNoticia"><b>Volta Notícias</b></a></li></ul> </div>

Compartilhar este post


Link para o post
Compartilhar em outros sites

- isso mesmo..

 

- para deixar inserir com ou sem.. altere o trecho

 

if (move_uploaded_file($_FILES["arquivo"]["tmp_name"],"../anexos/".$arquivo_nome)) {

$sql = "insert into noticias values (null, '$titulo', '$texto', current_date(), current_time(), '$fonte', '$arquivo_nome', '$nome_anexo')";

conecta();

mysql_query($sql) or die ("ERRO : ".mysql_error());

desconecta();

print "<center>Registro Inserido com Sucesso</center>";

} else {

print "<center><font color='#FF0000'><b>O arquivo não pode ser carregado.</b></font></center>";

}

 

 

para

 

if (move_uploaded_file($_FILES["arquivo"]["tmp_name"],"../anexos/".$arquivo_nome)) {   print "<center>Arquivo carregado com Sucesso</center> <BR> ";} else {   print "<center><font color='#FF0000'><b>O Arquivo não pode ser carregado.</b></font></center> <BR>";}$sql = "insert into noticias values (null, '$titulo', '$texto', current_date(), current_time(), '$fonte', '$arquivo_nome', '$nome_anexo')";conecta();mysql_query($sql) or die ("ERRO : ".mysql_error());desconecta();print "<center>Registro Inserido com Sucesso</center> <BR> ";

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.