Estoy intentando guardar material a través de un formulario, y a veces me guarda el material y otras no.
Además necesito el campo id que crea dicho material para otras consultas, yo no he conseguido ver el error, a ver si me podeis hechar una mano:
if ((($_FILES["userfile"]["type"] == "image/gif") || ($_FILES["userfile"]["type"] == "image/jpeg") || ($_FILES["userfile"]["type"] == "image/pjpeg")) || ($_FILES["userfile"]["type"] == "image/bmp") || ($_FILES["userfile"]["type"] == "image/x-windows-bmp") || ($_FILES["userfile"]["type"] == "application/octet-stream") || ($_FILES["userfile"]["type"] == "image/png") || ($_FILES["userfile"]["type"] == "application/msword") || ($_FILES["userfile"]["type"] == "application/pdf") || ($_FILES["userfile"]["type"] == "application/rtf") || ($_FILES["userfile"]["type"] == "application/excel") || ($_FILES["userfile"]["type"] == "application/x-compressed") || ($_FILES["userfile"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") && ($_FILES["userfile"]["size"] < 10485760)) {Tengo que la id de la tabla sea auto_increment
if ($_FILES["userfile"]["error"] > 0){
echo "Return Code: " . $_FILES["userfile"]["error"] . "<br />";
}else{
move_uploaded_file($_FILES["userfile"]["tmp_name"],"upload/" . $_FILES["userfile"]["name"]);
// Read the file
$tmpName = "upload/" . $_FILES["userfile"]["name"];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
unlink("upload/" . $_FILES["userfile"]["name"]);
$name_file = $_FILES["userfile"]["name"];
$type_file = $_FILES["userfile"]["type"];
// Create the query and insert
// into our database.
$guardar_material="INSERT INTO tabla_material (name,type,file,size,id_user) VALUES (\"".$_FILES["userfile"]["name"]."\",\"".$_FILES["userfile"]["type"]."\",\"".$data."\",\"".$_FILES["userfile"]["size"]."\",\"".$_POST["id_user"]."\")";
mysql_query($guardar_material, $link);
$id_material = mysql_insert_id();
}
}