Nada que me aparece la pagina en blanco. este es el codigo que tengo puesto ahora, solo me sale pantalla en blanco cuando coloco tu codigo.
Código PHP:
<?php require_once('Connections/compramos.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
// $len es la longitud que deseas que tenga el nuevo nombre
function random_name($len) {
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
$name = '';
for ($i = 0; $i < $len; ++$i)
$name .= substr($chars, (mt_rand() % strlen($chars)), 1);
return $name;
}
// Asegurate de agregar la extension correcta
$nuevo_nombre = random_name(15) . '.jpg';
if(!move_uploaded_file($_FILES['imagen']['tmp_name'], $nuevo_nombre)); {
echo 'No se pudo mover el archivo subido a su destino final, codigo de error: ' . $_FILES['imagen']['error'];
exit; // Detenemos el script para no insertar datos cuando hay errores.
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "envio")) {
$insertSQL = sprintf("INSERT INTO productos (nombre, descripcion, imagen) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['descripcion'], "text"),
GetSQLValueString("archivos/" . $nuevo_nombre, "text"));
mysql_select_db($database_compramos, $compramos);
$Result1 = mysql_query($insertSQL, $compramos) or die(mysql_error());
$insertGoTo = "pruebaenvio.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Documento sin título</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="envio" id="envio">
<label>
<input type="text" name="nombre" id="nombre" />
</label>
<p>
<label>
<textarea name="descripcion" id="descripcion" cols="45" rows="5"></textarea>
</label>
</p>
<p>
<label>
<input type="file" name="imagen" id="imagen" />
</label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Enviar" />
</label>
</p>
<input type="hidden" name="MM_insert" value="envio" />
</form>
</body>
</html>
Un saludo y gracias
Cita:
Iniciado por Triby
A esa linea le falta colocar al final punto y coma
; ... sin embargo, no es la forma mas optima para realizar el proceso, sino antes de insertar los datos:
Código php:
Ver original echo 'No se pudo mover el archivo subido a su destino final, codigo de error: ' . $_FILES['imagen']['error'];
exit; // Detenemos el script para no insertar datos cuando hay errores. }