Ir para conteúdo

POWERED BY:

Arquivado

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

vini.chuves

Problema

Recommended Posts

oi alguem pode analizar estes códioe e me dizer oq hé de errado? este código eu peguei aqui no imasters. sobre como fazer upload de imagem e nome pelo dreamweaver....a seguir o código...<?php require_once('Connections/upload.php'); ?><?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];}if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {$arquivo = $_FILES["foto"];$arquivo_nome = $arquivo["name"]; $insertSQL = sprintf("INSERT INTO tb_imagem (titulo, texto, foto) VALUES (%s, %s,'$arquivo_nome')", GetSQLValueString($HTTP_POST_VARS['titulo'], "text"), GetSQLValueString($HTTP_POST_VARS['texto'], "text"));set_time_limit(0);$diretorio = "arquivos";$id_arquivo = "foto";$nome_arquivo = $_FILES[$id_arquivo]["name"];$arquivo_temporario = $_FILES[$id_arquivo]["tmp_name"];move_uploaded_file($arquivo_temporario, "$diretorio/$nome_arquivo"); mysql_select_db($database_upload, $upload); $Result1 = mysql_query($insertSQL, $upload) or die(mysql_error()); $insertGoTo = "index.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));}?><html><head><title>Documento sem título</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <table align="center"> <tr valign="baseline"> <td nowrap align="right">Titulo:</td> <td><input type="text" name="titulo" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right" valign="top">Texto:</td> <td> <textarea name="texto" cols="50" rows="5"></textarea> </td> </tr> <tr valign="baseline"> <td nowrap align="right">Foto:</td> <td><input name="foto" type="file" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Inserir registro"></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"></form><p> </p> </body></html>ele diz dar erro nas linhas 34, 42, 43 e 55 mas não localizei o problema... se alguém puder ajudar fico agradecido...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ok... na linha 55, você usou sintaxe da forma errada....

Ao invés de

header(sprintf("Location: %s", $insertGoTo));
você deveria ter usado algo como
header("Location:". sprintf(s, $insertGoTo));
ou apenas
header("Location: $insertGoTo");
.

 

Coloque tb... ob_start(); no início do código, antes de tudo, e ob_end_flush(); no final do código. Do contrário, o header pode não funcionar.

 

Na linha 34, troque

$arquivo = $_FILES["foto"];$arquivo_nome = $arquivo["name"];
por
$arquivo_nome = $_FILES['foto']['name'];
.

 

Nas linhas 42 e 43 troque-as para

$nome_arquivo = $_FILES["foto"]["name"];$arquivo_temporario = $_FILES["foto"]["tmp_name"];

 

acho q com isso funciona. Mas cara..... esse script tá bastante bagunçado.... :(

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.