Ir para conteúdo

Arquivado

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

michel melo

upload de imagem

Recommended Posts

Pessoal estou usando este formulario a baixo para cadastra uma noticia e enviar uma imagem para o servidor mas nao estou conseguindo fazer isso alguem pode me ajudar a terminar isso

 

obrigado ja agora

 

<?php require_once('../../Connections/maquisintra.php'); ?><?php$data = date("d-m-Y");$hora = date("H:i:s");$novadata = substr($data,8,2) . "/" .substr($data,5,2) . "/" . substr($data,0,4);$novahora = substr($hora,0,2) . "h" .substr($hora,3,2) . "min";if (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) {  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {  $insertSQL = sprintf("INSERT INTO noticias1 (`data`, titulo, noticia, imagem) VALUES (%s, %s, %s, %s)",					   GetSQLValueString($_POST['data'], "date"),					   GetSQLValueString($_POST['titulo'], "text"),					   GetSQLValueString($_POST['texto'], "text"),					   GetSQLValueString($_POST['imagem'], "text"));  mysql_select_db($database_maquisintra, $maquisintra);  $Result1 = mysql_query($insertSQL, $maquisintra) or die(mysql_error());  $insertGoTo = "cadastrar.php";  if (isset($_SERVER['QUERY_STRING'])) {	$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";	$insertGoTo .= $_SERVER['QUERY_STRING'];  }  header(sprintf("Location: %s", $insertGoTo));}?><!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"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><link href="../../styles.css" rel="stylesheet" type="text/css" /></head><body><form method="post" name="form1" action="<?php echo $editFormAction; ?>">  <table align="center">	<tr valign="baseline">	  <td align="right" nowrap class="button">Titulo:</td>	  <td><input name="titulo" type="text" class="selectColorTable" value="" size="32"></td>	</tr>	<tr valign="baseline">	  <td align="right" nowrap class="button">Subtitulo:</td>	  <td><input name="subtitulo" type="text" class="selectColorTable" value="" size="32"></td>	</tr>	<tr valign="baseline">	  <td align="right" nowrap class="button">Texto:</td>	  <td><textarea name="texto" cols="32" rows="3" wrap="virtual" class="selectColorTable"></textarea></td>	</tr>	<tr valign="baseline">	  <td align="right" nowrap class="button">Imagem:</td>	  <td align="right" nowrap><div align="left">		<input name="imagem" type="file" id="imagem" />	  </div>		</label></td>	</tr>	<tr valign="baseline">	  <td colspan="2" align="right" nowrap><div align="center">		<input type="submit" class="selectColorOn" value="Cadastrar">	  </div></td>	</tr>  </table>  <input type="hidden" name="data" value="<?php echo $data ?>">  <input type="hidden" name="hora" value="<?php echo $hora ?>">  <input type="hidden" name="MM_insert" value="form1"></form><p> </p></body></html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

fiz assim mas deu erro:

Possivel ataque de upload! Aqui esta alguma informação:Array()

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {  $insertSQL = sprintf("INSERT INTO noticias1 (`data`, titulo, noticia, imagem) VALUES (%s, %s, %s, %s)",					   GetSQLValueString($_POST['data'], "date"),					   GetSQLValueString($_POST['titulo'], "text"),					   GetSQLValueString($_POST['texto'], "text"),					   GetSQLValueString($_POST['imagem'], "text"));  mysql_select_db($database_maquisintra, $maquisintra);  $Result1 = mysql_query($insertSQL, $maquisintra) or die(mysql_error());//$uploaddir = 'C:\apache2triad\htdocs\maquisintra\admin\img_noticias';$uploadfile = $uploaddir . $_FILES['imagem']['name'];print "<pre>";if (move_uploaded_file($_FILES['imagem']['tmp_name'], $uploaddir . $_FILES['imagem']['name'])) {	print "O arquivo é valido e foi carregado com sucesso. Aqui esta alguma informação:\n";	print_r($_FILES);} else {	print "Possivel ataque de upload! Aqui esta alguma informação:\n";	print_r($_FILES);}print "</pre>";//

Compartilhar este post


Link para o post
Compartilhar em outros sites

Só para lembrar que na tag <form> tem que ter enctype="multipart/form-data"...senão ele não vai enviar arquivo algum!

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.