Como estan gente, primeramente felicidades por las fietas. :)
les cuento mi problema estoy haciendo un sistema de noticias con imagenes, pero no logro que en el index de mi pagina aparesca el thumbnail solamente aparece una imagen chiquita rota. estoy trabajando con wampserver 2.2... con windows xp el error que me sale es el siguiente:
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'c:/windows/temp/thumbtemp' for writing: Permission denied in C:\wamp\www\2012\admin.php on line 43
Warning: fopen(c:/windows/temp/thumbtemp) [function.fopen]: failed to open stream: Permission denied in C:\wamp\www\2012\admin.php on line 58
Warning: fread() expects parameter 1 to be resource, boolean given in C:\wamp\www\2012\admin.php on line 59
Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp\www\2012\admin.php on line 61
El codigo es el siguiente:
<?php include_once("config.php"); ?>
<?php
// Verificamos que el formulario no ha sido enviado aun
$postback = (isset($_POST["enviar"])) ? true : false;
if($postback){
// errores
error_reporting(E_ALL);
# Altura de el thumbnail en píxeles
define("ALTURA", 100);
# Nombre del archivo temporal del thumbnail
define("NAMETHUMB", "c:/windows/temp/thumbtemp");
define("DBHOST", "$servidor");
define("DBNAME", "$database");
define("DBUSER", "$usuario");
define("DBPASSWORD", "$password");
$mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png");
$name = $_FILES["foto"]["name"];
$type = $_FILES["foto"]["type"];
$tmp_name = $_FILES["foto"]["tmp_name"];
$size = $_FILES["foto"]["size"];
if(!in_array($type, $mimetypes))
die("Seleciones una Imagen o El archivo que subiste no es una Imagen válida");
switch($type) {
case $mimetypes[0]:
case $mimetypes[1]:
$img = imagecreatefromjpeg($tmp_name);
break;
case $mimetypes[2]:
$img = imagecreatefromgif($tmp_name);
break;
case $mimetypes[3]:
$img = imagecreatefrompng($tmp_name);
break;
}
$datos = getimagesize($tmp_name);
$ratio = ($datos[1]/ALTURA);
$ancho = round($datos[0]/$ratio);
$thumb = imagecreatetruecolor($ancho, ALTURA);
imagecopyresized($thumb, $img, 0, 0, 0, 0, $ancho, ALTURA, $datos[0], $datos[1]);
switch($type) {
case $mimetypes[0]:
case $mimetypes[1]:
imagejpeg($thumb, NAMETHUMB);
break;
case $mimetypes[2]:
imagegif($thumb, NAMETHUMB);
break;
case $mimetypes[3]:
imagepng($thumb, NAMETHUMB);
break;
}
# foto original
$fp = fopen($tmp_name, "rb");
$tfoto = fread($fp, filesize($tmp_name));
$tfoto = addslashes($tfoto);
fclose($fp);
# thumbnail
$fp = fopen(NAMETHUMB, "rb");
$tthumb = fread($fp, filesize(NAMETHUMB));
$tthumb = addslashes($tthumb);
fclose($fp);
// Borra archivos temporales
@unlink($tmp_name);
@unlink(NAMETHUMB);
//proceso de almacenamiento
$fuente = $_POST["fuente"];
$categoria = $_POST["categoria"];
$titulo = (ucfirst($_POST["titulo"]));
$subtitulo = $_POST["subtitulo"];
$detalle = (nl2br(htmlspecialchars(urldecode($_POST["detalle"]))));
$link = mysql_connect(DBHOST, DBUSER, DBPASSWORD) or die(mysql_error($link));;
mysql_select_db(DBNAME, $link) or die(mysql_error($link));
$sql = "INSERT INTO noticia(fuente, categoria, titulo, subtitulo, detalle, foto, thumb, mime)
VALUES
('$fuente', '$categoria', '$titulo', '$subtitulo', '$detalle', '$tfoto', '$tthumb', '$type')";
mysql_query($sql, $link) or die(mysql_error($link));
echo " Archivos Guardados, correctamente ";
exit();
}
?>
<html>
<head>
<title>Mi Sistema de Noticia</title>
</head>
<body>
<form name="frmimage" id="frmimage" method="post"
enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>">
<p>Titulo<br />
<input name="titulo" type="text" class="text" id="titulo" />
</p>
<p> Subtitulo<br />
<textarea name="subtitulo" id="subtitulo" cols="60" rows="5" tabindex="4"></textarea>
</p>
<p> Detalle<br />
<textarea name="detalle" id="detalle" cols="60" rows="10" tabindex="4"></textarea>
</p>
<p>
Seleciones una imagen<br>
<input name="foto" type="file" class="text" id="foto" />
</p>
<p>
</p>
Fuente de la Noticia <br>
<input name="fuente" type="text" class="text" id="fuente" />
</p>
<p>
Categoria:<br>
<select name="categoria" id="categoria">
<option>PHP</option>
<option>MySql</option>
<option>CSS</option>
<option>AJAX</option>
<option>Seguridad</option>
</select>
</p>
<p>
<input name="fecha" type="hidden" id="fecha" />
<input name="enviar" type="submit" id="enviar" value="Publicar" />
</p>
</form>
</body>
</html>
como tengo windows lei que se tiene que ocupar esta linea: define("NAMETHUMB", "c:/windows/temp/thumbtemp");
yo no tenia la carpeta thumbtemp entonces la cree yo mismo!
el archivo php_gd2.dll está funcionando correctamente!
el sistema tiene las siguientes paginas:
admin.php: formulario para cargar la noticia. (aqui está el problema)
config.php: nombre de la base de datos, usuario etc.
Images_bd.php: procesa las imagenes.
detalle.php: muesta la noticia completa con la imagen en tamaño real.
index.php: y bueno aqui muestra un "resumen" de la noticia y el thumbnail
el error es solamente que no muestra el thumbnail como dije anteriormente aparece una imagen rota.
Espero me puedan ayudar, ya busque bastante y probé varias cosas, pero ninguna dio resultado. un saludo.



Citar


Marcadores