PHP - Gestor de noticias.

 
Vista:

Gestor de noticias.

Publicado por Luis (2 intervenciones) el 20/10/2011 00:11:18
Buenas, estoy intentando crear un gestor de noticias para mi web, algo sencillo, no muy complicado, pero vistoso. Con la opción de subir una imagen. Bueno y encontre un tutorial en internet, pero lo puse a funcionar y me han salido los siguientes errores.


Notice: Undefined variable: usuario in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 15

Warning: imagejpeg() [function.imagejpeg]: Unable to open '/tmp/thumbtemp' for writing in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 44

Warning: fopen(/tmp/thumbtemp) [function.fopen]: failed to open stream: No such file or directory in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 59

Warning: filesize() [function.filesize]: Stat failed for /tmp/thumbtemp (errno=2 - No such file or directory) in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 60

Warning: fread(): supplied argument is not a valid stream resource in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 60

Warning: fclose(): supplied argument is not a valid stream resource in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 62

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: YES) in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 72

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in C:\inetpub\vhosts\131innova.es\httpdocs\web\admin.php on line 72

En el servidor que lo he querido instalar es Windows no Linux, y creo que eso proboca vario de los fallos.

A continuacion les pongo el código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?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", "/tmp/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>

Si alguien sabe de algun gestor de noticias de codigo libre que funcione y tenga la opción de subir una imagen, y me lo puede aconsejar se lo agradeceria...

Gracias de antemano!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Gestor de noticias.

Publicado por xve (6935 intervenciones) el 20/10/2011 10:10:39
Hola Luis, tienes varios warning y diferentes...

Unable to open '/tmp/thumbtemp
NO puede abrir esta carpeta o archivo... revisa que existe y que tenga derechos de escritura el usuario que ejecuta el servidor web.

Access denied for user 'ODBC'@'localhost'
El usuario que accede a la base de datos, es erróneo o tiene la contraseña errónea.

coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar