Ver Mensaje Individual
  #5 (permalink)  
Antiguo 16/05/2011, 03:22
cabritillo77
 
Fecha de Ingreso: mayo-2011
Mensajes: 33
Antigüedad: 13 años
Puntos: 4
Solucionado

Despues de mucho probar encontre la solucion, aqui la dejo por si a alguien le viene bien:(renombre el fichero a add-noticia-imagen.php)
Como veis el formulario esta incluido dentro del php.
Cualquier cosa no dudeis en preguntarme

add-noticia-imagen.php
Código PHP:
<?php
// incluimos el archivo de conexion
include ('db-cnx.php');
// recibimos el formulario
if(isset($_POST['enviar']) && $_POST['enviar'] == 'Enviar'){
// comprobamos que el formulario no envie campos vacios
if(!empty($_POST['notTitulo']) && $_POST['notTexto'] &&
$_POST['notCategoriaID']){
// creamos las variables y les asignamos los valores a insertar
$notTitulo $_POST['notTitulo'];
$notTexto $_POST['notTexto'];
$notCategoriaID $_POST['notCategoriaID'];
$notTitulo strtoupper ($notTitulo);
$notTexto ucfirst ($notTexto);
$nombre_archivo $_FILES["foto"]["name"];  
$tipo_archivo $_FILES["foto"]["type"];  
$tamano_archivo $_FILES["foto"]["size"];

if (!((
strpos($tipo_archivo"gif") || strpos($tipo_archivo"jpeg")) && (    $tamano_archivo 1000000))) 
{  
    echo 
"La extensión o el tamaño de los archivos no es correcta. <br><br><table><tr><td><li>Se permiten archivos .gif o .jpg<br><li>se permiten archivos de 1Mg máximo.</td></tr></table>";
}
else 
{  
    
$nom_img$nombre_archivo
     
    
$directorio 'imagesr/';
    if (
move_uploaded_file($_FILES['foto']['tmp_name'],$directorio "/" $nom_img)) 
    {
    
  
// hacemos el INSERT en la BD
$sqlInsertNot mysql_query("INSERT INTO sn_noticias
(notTitulo, notTexto, notCategoriaID, foto)
VALUES ('$notTitulo', '$notTexto', '$notCategoriaID', '$nom_img')"
,
$db_link) or die(mysql_error());

// si el formulario envia algun campo vacio
// enviamos un mensaje de error
echo "La noticia se publico correctamente";
}else{
    
echo 
"error al subir la foto";
}

}
}else{
echo 
"Debe introducir Titulo, Texto y Categoria de la Noticia";
}
}
?>
<!-- el formulario -->
<div style="position: absolute; left: 300; top: 50; width: 300; height: 500">
<form name="noticia" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"
>
<body bgcolor="#FFE821">
<p>
Título de la Noticia<br />
<input type="text" name="notTitulo" size="50" />
</p>
<p>
Texto de la Noticia<br />
<textarea name="notTexto" rows="10" cols="50"></textarea>
</p>
<p>
Inserta imagen<br />
<input type="file" name="foto" size="50" />
<p>
Categoría<br />
<select name="notCategoriaID">

<option value="">Escoger de la Lista</option>


<?php
// asignamos una categoria a la noticia
// mediante un select
$sqlQueryCat mysql_query("SELECT * FROM sn_categorias"$db_link)
or die(
mysql_error());
// creamos un bucle while
// que nos muestre todas las categorias
// que tenemos guardadas en la BD
while($rowCat mysql_fetch_array($sqlQueryCat)){
echo 
"<option value='$rowCat[cat_ID]'>$rowCat[catCategoria]</option>";
}
?>
</select>
</p>
<p>
<input type="submit" name="enviar" value="Enviar" />
</p>
</form>
<br><br>
<a href="indexr.php">Ver Noticias</a>
<br><br>
<a href="add.categoria.php">Añadir Nueva Categoria</a>

</div>
La carpeta /imagesr debe tener permiso chmod 775 para que se suban las imagenes y debe estar en el mismo sitio donde esten estas paginas que son el gestor de noticias.



Y el siguiente es uno de los php donde muestro las imagenes:
list-noticia-campeonatos.php
Código PHP:
<?
// verificamos si se ha enviado
// alguna variable via GET
if(isset($_GET['id']) && $_GET['categoria']){
    
// asignamos los valores
    // a las variables que usaremos
    
$cat_ID $_GET['id'];
    
$categoria $_GET['categoria'];
}
// armamos la consulta
$sqlQueryNot mysql_query("SELECT notTitulo, notTexto, foto FROM sn_noticias where notCategoriaID='1' ORDER BY not_ID DESC LIMIT 4"$db_link) or die(mysql_error);
//Declarar el array 
$ArrayTitulo = array(notTitulo);
$ArrayTexto = array(notTexto); 
$Arrayfoto = array(foto);    
  while(
$rowNot mysql_fetch_array($sqlQueryNot)){                
$ArrayTitulo[]= $rowNot[notTitulo];
$ArrayTexto[]= $rowNot[notTexto];
$Arrayfoto[]= $rowNot[foto];
}
 
?>   
<body bgcolor="#FFE821">

<div style="position: absolute; left: 280; top: 230; width: 240; height: 909; float:left">

<table border="0" cellpadding="0" cellspacing="0"  width="279"  bgcolor="#ffffff">

<?include("docs/esquinasarriba.txt");?>

<td class="fondoblanco">

<table width="257">

<tr>

<td colspan="2" align="center"><font color="#ff7f00"><b>CAMPEONATOS</b></font>

</td>

</tr>

<tr>
<td colspan="2" align="center"><a href="/resultadoscv2011.php">Palmares Equipos 2011</a></td>
</tr>"

<tr>
<td align="left"><a href="docs/CLUB DE TENIS TORREVIEJA-M.pdf">Ranking Masculino</a></td>
<td align="right"><a href="docs/CLUB DE TENIS TORREVIEJA-F.pdf">Ranking Femenino</a></td>
</tr>

</table>

<HR>


<table class="fondoblanco" width="257">

<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[1]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[1]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[1]; ?>"><img src="imagesr/<? echo $Arrayfoto[1]; ?>"
width="100" height="100">
<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->

<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[2]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[2]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[2]; ?>"><img src="imagesr/<? echo $Arrayfoto[2]; ?>" width="100" height="100"> 
<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->




<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[3]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[3]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[3]; ?>"><img src="imagesr/<? echo $Arrayfoto[3]; ?>" width="100" height="100">
<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->




<tr>

<td align="center"><font color="#ff7f00"><b><? echo $ArrayTitulo[4]; ?></b></font>

</td>
</tr>

<tr>
<td align="center">
<p>
<? echo $ArrayTexto[4]; ?>
<br><br>
</p>

<br><br>
<a href="imagesr/<? echo $Arrayfoto[4]; ?>"><img src="imagesr/<? echo $Arrayfoto[4]; ?>" width="100" height="100">
<hr>
</td>
</tr>

<!------------------------------------------------------------------------------------->


</table>




<?include("docs/esquinasabajo.txt");?>

</table>
<br><br>
</div>
</body>

Las tablas son

sn_noticias
Código:
CREATE TABLE `sn_noticias` (
`not_ID` int(11) NOT NULL auto_increment,
`notTitulo` varchar(255) NOT NULL,
`notTexto` text NOT NULL,
`notCategoriaID` int(11) NOT NULL,
`fotos` varchar(100) NOT NULL,
PRIMARY KEY  (`not_ID`)
) ENGINE=MyISAM;
sn_categorias

Código:
CREATE TABLE `sn_categorias` (
`cat_ID` int(11) NOT NULL auto_increment,
`catCategoria` varchar(100) NOT NULL,
PRIMARY KEY  (`cat_ID`)
) ENGINE=MyISAM;