Ya hace tiempo (días) que estoy tratando de hacer que funcione un upload que extraiga la sesion y que la guarde en un base de datos junto con los datos del archivo subido. Por el momento no me interesa fijar la extensión del archivo solo quiero pasar esta traba. ¿Cómo puedo hacer? El sistema de autentificación es sacado de una web "SimpleAuth" la última version 1.3. Para hacer referencia al usuario e imprimirlo hay que hacer esto"
Código HTML:
<? include_once("config.php");
// Check user logged in already:
checkLoggedIn("yes");
print("Welcome to the members page <b>".$_SESSION["login"]."</b><br>\n");
print("Your password is: <b>".$_SESSION["password"]."</b><br>\n");
print("<a href=\"logout.php"."\">Logout</a>"); ?>
La conexión a la base de datos.
Un include_once("../functions.php") que tiene las funciones como la conexion, la intruduccion de nuevos usuarios con usuario y contraseña y chekea si esta conectado cone este código
Código HTML:
function checkLoggedIn($status){ /* Function to check whether a user is logged in or not: This is a function that checks if a user is already logged in or not, depending on the value of $status which is passed in as an argument. If $status is 'yes', we check if the user is already logged in; If $status is 'no', we check if the user is NOT already logged in. */ switch($status){ // if yes, check user is logged in: // ie for actions where, yes, user must be logged in(!) case "yes": if(!isset($_SESSION["loggedIn"])){ header("Location: ../login.php"); exit; } break; // if no, check NOT logged in: // ie for actions where user can't already be logged in // (ie for joining up or logging in) case "no": /* The '===' operator differs slightly from the '==' equality operator. $a === $b if and only if $a is equal to $b AND $a is the same variable type as $b. for example, if: $a="2"; <-- $a is a string here $b=2; <-- $b is an integer here then this test returns false: if($a===$b) whereas this test returns true: if($a==$b) */ if(isset($_SESSION["loggedIn"]) && $_SESSION["loggedIn"] === true ){ header("Location: ../members.php"); } break; } // if got here, all ok, return true: return true; } // end func checkLoggedIn($status)
Código HTML:
<? include_once ("config.php"); checkLoggedIn("yes"); ?> <html> <head> <title>Inet2phone v0.1 beta</title> </head> <body> <?php if ($_FILES['userfile']['name'] == '') { print "<form action=\"guardar.php\" method=\"POST\" enctype=\"multipart/form-data\"> <b>Nombre: <input type=\"text\" name=\"nombre\" size=\"20\" maxlenght=\"100\"><br> <b>Descripción: <br> <input type=\"text\" name=\"cadenatexto\" size=\"20\" maxlength=\"100\"><br> <BR> <B>Tipo de Archivo: <SELECT NAME=\"archivo_tipo\"> <OPTION VALUE='juego'>Juego <OPTION VALUE='ringtone'>Ringtone <OPTION VALUE='aplicacion'>Aplicacion <OPTION VALUE='imagen'>Imagen </SELECT><br> <input type='hidden' name='MAX_FILE_SIZE' value='100000'> <br> <br> <b>Enviar un nuevo archivo: <br> <input name='userfile' type='file'><br> <br> <input type='submit' value='Enviar'><br> </form>\n"; } else { /*conexion*/ //tomo el valor de un elemento de tipo texto del formulario $cadenatexto = mysql_real_escape_string($_POST['cadenatexto']); $directorio = "imagenes/"; //directorio donde se guardan los archivos $archivo_tipo = mysql_real_escape_string($_POST['archivo_tipo']); $nombre = mysql_real_escape_string($_POST['nombre']); $nombre_archivo = $_FILES['userfile']['name']; $tipo_archivo = $_FILES['userfile']['type']; $tamano_archivo = $_FILES['userfile']['size']; //compruebo si las características del archivo son las que deseo $nombre_archivo = ereg_replace(" ", "", $nombre_archivo); //borra espacios libres en nombre de archivo if (!empty($_FILES['userfile']['tmp_name'])){ if (move_uploaded_file($_FILES['userfile']['tmp_name'],$directorio . $nombre_archivo)){ echo "<big>El archivo ha sido cargado correctamente."; $ssql_=mysql_query("SELECT * FROM contenidos WHERE login='".$_SESSION[login]."'")or die(mysql_error()); $query = "INSERT INTO imagenes (id,nombre,tipo,tamano,descripcion,nombrearchivo,login) VALUES ('$id','$nombre','$archivo_tipo','$tamano_archivo','$cadenatexto','$nombre_archivo','$login')"; $result = mysql_query($query) or die ("<BR>No pudo agregar las cosas a la base de datos"); //agrego los datos obtenidos echo "<br> "; echo "<TABLE>Nombre".$nombre.""; echo "<TR>Tipo de archivo".$tipo_archivo.""; echo "<TR>Tamaño de archivo".$tamano_archivo.""; echo "<TR>Nombre de archivo".$nombre_archivo.""; echo "<tr>Nombre de Usuario".$currentuser.""; } else { echo "Ocurrió algún error al subir el fichero. No pudo guardarse."; // me da este error } } } ?> <br> </body> </html>
Ocurrió algún error al subir el fichero. No pudo guardarse.
Prové miles de formas, investigué millones de sitios, leí la página oficial de php pero no logré nada, es más la página se me volvia blanca :S
AYUDA!