<?php
ini_set('upload_max_filesize', '132M');
ini_set('post_max_size', '32M');
ini_set('log_errors',1);
ini_set('error_log','uploads/');
$hostname = 'localhost';
$database = 'bsite';
$username = 'u514981266_mmapp';
$password = '51315sk8';
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["uploadBtn"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["uploadBtn"]["tmp_name"]);
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["uploadBtn"]["tmp_name"], $target_file)) {
	$mysqli = new mysqli($hostname, $username,$password, $database);
if ($mysqli -> connect_errno) {
die( "Fallo la conexión a MySQL: (" . $mysqli -> mysqli_connect_errno() 
. ") " . $mysqli -> mysqli_connect_error());
}
else
echo "Conexión exitosa!";
//MySQLi
if ($mysqli->query("insert into blog values(null,'".$_POST['pn']."','".$_POST['desc']."','".$_FILES["uploadBtn"]["name"]."')") === TRUE) {
printf($mysqli->affected_rows." Filas afectadas");
}
else
echo "Error al ejecutar el comando:".$mysqli->error;
        echo "The file ". basename( $_FILES["uploadBtn"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file. ";
		switch ($_FILES['uploadBtn'] ['error'])
 {  case 1:
           print '<p> The file is bigger than this PHP installation allows</p>';
           break;
    case 2:
           print '<p> The file is bigger than this form allows</p>';
           break;
    case 3:
           print '<p> Only part of the file was uploaded</p>';
           break;
    case 4:
           print '<p> No file was uploaded</p>';
           break;
 }
    }
}
?>
<script>
window.location = "index.php";
</script>
<?php
?>