Ir para conteúdo

Arquivado

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

André Ricardo Theodoro

Erro ao deletar fotos

Recommended Posts

http://forum.imasters.com.br/public/style_emoticons/default/upset.gif

Eae Pessoal!

Estou patinando em um erro e preciso de ajuda, eu quero excluir do meu banco de dados e do diretório as fotos e legendas das fotos mas não estou conseguindo formular o código!

Estava seguindo as dicas desse artigo :http://www.imasters.com.br/artigo/3875/mysql/sistema_de_publicacao_de_fotos_com_comentarios_alterar_dados_e_foto/

Mas ele não é muito esclarecedor, tendo em vista que eu não uso a conexão que ele criou, pois uso a minha conexão conecta, mas não entendo o erro.....

Se alguém pudesse me ajudar ficaria mto grato! :(

O código é este:

<?php require_once('conecta.php'); ?> <?php $colname_rsAlterarDadosFoto = "-1"; if (isset($_GET['foto_id'])) {   $colname_rsAlterarDadosFoto = (get_magic_quotes_gpc()) ? $_GET['foto_id'] : addslashes($_GET['foto_id']); } $s = ('foto_id');mysql_select_db($database); $query_rsAlterarDadosFoto = sprintf("SELECT * FROM a_fotos WHERE foto_id = %s", $colname_rsAlterarDadosFoto); $rsAlterarDadosFoto = mysql_query($query_rsAlterarDadosFoto) or die(mysql_error()); $row_rsAlterarDadosFoto = mysql_fetch_assoc($rsAlterarDadosFoto); $totalRows_rsAlterarDadosFoto = mysql_num_rows($rsAlterarDadosFoto); function 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 = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) {   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } $foto = $row_rsAlterarDadosFoto['foto_foto']; $fotoTmp = $_FILES["foto_foto"]["tmp_name"]; if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {   $updateSQL = sprintf("UPDATE fotos SET foto_foto='$foto', foto_titulo=%s, foto_legenda=%s WHERE foto_id=%s", 					   GetSQLValueString($_POST['foto_titulo'], "text"), 					   GetSQLValueString($_POST['foto_legenda'], "text"), 					   GetSQLValueString($_POST['foto_id'], "int")); function geraImg($img, $max_x, $max_y, $imgNome) { 	//pega o tamanho da imagem ($original_x, $original_y) 	list($width, $height) = getimagesize($img); 	$original_x = $width; 	$original_y = $height; 	// se a largura for maior que altura acho a porcentagem 	if($original_x > $original_y) { 	   $porcentagem = (100 * $max_x) / $original_x;	   	} 	else { 	   $porcentagem = (100 * $max_y) / $original_y;   	} 	$tamanho_x = $original_x * ($porcentagem / 100); 	$tamanho_y = $original_y * ($porcentagem / 100); 	$image_p = imagecreatetruecolor($tamanho_x, $tamanho_y); 	$image = imagecreatefromjpeg($img); 	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height); 	return imagejpeg($image_p, $imgNome, 100); } geraImg($fotoTmp, 640, 480, "../fotos/".$foto);   mysql_select_db($database);   $Result1 = mysql_query($updateSQL) or die(mysql_error());   $updateGoTo = "index.php";   if (isset($_SERVER['QUERY_STRING'])) { 	$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; 	$updateGoTo .= $_SERVER['QUERY_STRING'];   }   header(sprintf("Location: %s", $updateGoTo)); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>editor de foto</title> </head> <body> <h1>Alterar os dados e a foto</h1> <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1"> 		<table align="center"> 				<tr valign="baseline"> 						<td nowrap align="right">Foto:</td> 						<td><input name="foto_foto" type="file" size="32"></td> 				</tr> 				<tr valign="baseline"> 						<td nowrap align="right">Título::</td> 						<td><input type="text" name="foto_titulo" value="<?php echo $row_rsAlterarDadosFoto['foto_titulo']; ?>" size="32"></td> 				</tr> 				<tr valign="baseline"> 						<td nowrap align="right">Legenda:</td> 						<td><textarea name="foto_legenda" cols="40" rows="6"><?php echo $row_rsAlterarDadosFoto['foto_legenda']; ?></textarea></td> 				</tr> 				<tr valign="baseline"> 						<td nowrap align="right"> </td> 						<td><input type="submit" value="Atualizar"></td> 				</tr> 		</table> 		<input type="hidden" name="MM_update" value="form1"> 		<input type="hidden" name="foto_id" value="<?php echo $row_rsAlterarDadosFoto['foto_id']; ?>"> </form> <p> </p> </body> </html> <?php mysql_free_result($rsAlterarDadosFoto); ?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa!!!!!

Postei o código errado!!

Dsculpe!!!

o código que eu estou usando é este:

<title>Deletar fotos</title><?php require_once 'conecta.php'; ?><?php ?><form action="" method="get">  <p>Confirmar a exclusão da foto? </p>  <p>	<input name="Input" type="submit" value="Sim">	<input name="foto_id" type="hidden" id="foto_id2">	<input type="submit" name="Submit" value="Cancelar"></p></form>
O roblema é justamente este, não consigo criar um código pra excluir do diretório e do banco de dados as fotos.......e no artigo explica com um metódo que não posso usar na empresa!

Compartilhar este post


Link para o post
Compartilhar em outros sites

pra deletar o arquivo, é mole, é só usar o comando unlink("nomedoarquivo");e pra deletar do DB, se for mySQL, é só criar uma rotina que execute o script: DELETE FROM tabela WHERE codigo = $codigo (algo do tipo...)

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.