Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/10/2012, 13:28
vludenag
 
Fecha de Ingreso: julio-2012
Mensajes: 5
Antigüedad: 11 años, 9 meses
Puntos: 0
Error en formulario con imagenes.

Estimados tengo el siguiente codigo en un formulario para añadir un plato pero no me funciona al añadir las imagenes. agregue q se vieran los valores de las variables y trate de resolverlo pero aun no puedo se queda en la condicional de formato de imagen y de tamaño. Alguien puede ayudarme gracias.

<?php
require "variablesimagen.php";
require_once('cntotro.php');
require "conexionprueba.php"; //necesario para cargar los valores de los select categoria y estado

// Conexión con la base de datos
$cn = fnConnect( $msg );
// Leer lista de categorias
$sql = "select id_categoria, nombre_categoria from categoria";
$cates = mysql_query( $sql, $cn );
// Leer lista de estado
$sql = "select id_estado, nombre_estado from estadoplato ";
$estad = mysql_query( $sql, $cn );


if (isset($_POST['submit'])) {
// Recopila los campos del formulario
$nombre = $_POST['nombre'];
$costo = $_POST['costo'];
$descripcion = $_POST['descripcion'];
$categoria = $_POST['categoria'];
$estado = $_POST['estado'];
$screenshot = $_FILES['screenshot']['name'];
$screenshot_type = $_FILES['screenshot']['type'];
$screenshot_size = $_FILES['screenshot']['size'];


echo $nombre;
echo $costo;
echo $descripcion;
echo $categoria;
echo $estado;
echo $name;


if (!empty($nombre) && !empty($costo) && !empty($screenshot)) {
if ((($screenshot_type == 'images/gif') || ($screenshot_type == 'images/jpeg') || ($screenshot_type == 'images/pjpeg') || ($screenshot_type == 'images/png'))
&& ($screenshot_size > 0) && ($screenshot_size <= GW_MAXFILESIZE)) {
if ($_FILES['screenshot']['error'] == 0) {
// Move the file to the target upload folder
$target = GW_UPLOADPATH . $screenshot;
if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Write the data to the database
$query = "INSERT INTO plato VALUES (0, '$nombre', '$costo', '$descripcion', '$categoria', '$estado', '$screenshot')";
mysqli_query($dbc, $query);

// Confirm success with the user
echo '<p>Thanks for adding your new high score! It will be reviewed and added to the high score list as soon as possible.</p>';
echo '<p><strong>Name:</strong> ' . $nombre . '<br />';
echo '<strong>Score:</strong> ' . $costo . '<br />';
echo '<img src="' . GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>';
echo '<p><a href="destino.php">&lt;&lt; Back to high scores</a></p>';

// Clear the score data to clear the form
$nombre = "";
$costo = "";
$screenshot = "";

mysqli_close($dbc);
}
else {
echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>';
}
}
}
else {
echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>';
}

// Try to delete the temporary screen shot image file
@unlink($_FILES['screenshot']['tmp_name']);
}
else {
echo '<p class="error">Please enter all of the information to add your high score.</p>';
}
}
?>

<hr />
<form enctype="multipart/form-data" <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="443" border='1'>
<tr>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" />
<td width="126" height="42" class="celda"> Nombre : (*)</td>
<td width="301"><input type="text" name="nombre" value="<?php if (!empty($nombre)) echo $nombre; ?>"></td>
</tr>
<tr>
<td height="40"><span class="celda">Costo</span>: (*)</td>
<td><input type="text" name="costo" value="<?php if (!empty($costo)) echo $costo; ?>"></td>
</tr>
<tr>
<td height="122"><span class="celda">Descripcion</span> :</td>
<td><textarea name="descripcion" id="descripcion" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td height="41"><span class="celda">Categoria</span> :</td>
<td><select name="categoria" size="1" id="categoria">
<?php while( $row = mysql_fetch_assoc( $cates ) ) {?>
<option value="<?php echo($row["id_categoria"]) ?>"> <?php echo($row["nombre_categoria"]) ?> </option>
<?php } ?>
</select></td>
</tr>
<tr>
<td height="37"><span class="celda">Estado</span> :</td>
<td><select name="estado" size="1" id="estado">
<?php while( $row = mysql_fetch_assoc( $estad ) ) {?>
<option value="<?php echo($row["id_estado"]) ?>"> <?php echo($row["nombre_estado"]) ?> </option>
<?php } ?>
</select></td>
</tr>
<tr>
<td height="41"><span class="celda">Imagen :</span></td>
<td><input type="file" id="screenshot" name="screenshot" /></td>

</tr>
<tr>
<td colspan="2" align="center"><input name="submit" type="submit" id="submit" value="Grabar">
<input name="limpiar" type="reset" id="limpiar" value="Limpiar"></td>
</table>
</form>



</body>
</html>