Perfetto, grazie dell'aiuto. Questo è il codice con l'implementazione dell'uploading, anche se non ho controllato se funziona anche il multiple upload..
Codice PHP:
<?php
//inizializzo sessione.
session_start();
if(isset($_SESSION['userSession'])!="")
{
header("Location: home.php");
}
include_once 'dbconnect.php';
if(isset($_POST['btn-signup']))
{
$uname = $MySQLi_CON->real_escape_string(trim($_POST['user_name']));
$email = $MySQLi_CON->real_escape_string(trim($_POST['user_email']));
$upass = $MySQLi_CON->real_escape_string(trim($_POST['password']));
//password criptata
$new_password = md5($upass);
//parametri della foto da caricare
$target_dir = "myupload/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
$msg = "<div class='alert alert-danger'>
<span class='glyphicon glyphicon-info-sign'></span> Sorry, this file is not an image.
</div>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
$msg = "<div class='alert alert-danger'>
<span class='glyphicon glyphicon-info-sign'></span> Sorry, only JPG, JPEG, PNG & GIF files are allowed.
</div>";
$uploadOk = 0;
}
// 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["image"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$check_email = $MySQLi_CON->query("SELECT user_email FROM users WHERE user_email='$email'");
$count=$check_email->num_rows;
if($count==0){
$query = "INSERT INTO users(user_name,user_email,user_pass, user_image) VALUES('$uname','$email','$new_password','$target_file')";
if($MySQLi_CON->query($query))
{
$msg = "<div class='alert alert-success'>
<span class='glyphicon glyphicon-info-sign'></span> successfully registered !
</div>";
}
else
{
$msg = "<div class='alert alert-danger'>
<span class='glyphicon glyphicon-info-sign'></span> error while registering !
</div>";
}
}
else {
$msg = "<div class='alert alert-danger'>
<span class='glyphicon glyphicon-info-sign'></span> sorry email already taken !
</div>";
}
$MySQLi_CON->close();
}
?>
<html>
<head>
<title>Login & Registration System</title>
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
</head>
<body>
<div class="signin-form">
<div class="container">
<form class="form-signin" method="post" enctype="multipart/form-data" id="register-form">
<h2 class="form-signin-heading">Sign Up</h2><hr />
<?php
if(isset($msg)){
echo $msg;
}
else {
?>
<div class='alert alert-info'>
<span class='glyphicon glyphicon-asterisk'></span> all the fields are mandatory !
</div>
<?php
}
?>
<div class="form-group">
<input type="text" class="form-control" placeholder="Username" name="user_name" required />
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email address" name="user_email" required />
<span id="check-e"></span>
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" name="password" required />
</div>
<input type="file" class="form-control" name="image" />
<hr />
<div class="form-group">
<button type="submit" class="btn btn-default" name="btn-signup">
<span class="glyphicon glyphicon-log-in"></span> Create Account
</button>
<a href="index.php" class="btn btn-default" style="float:right;">Log In Here</a>
</div>
</form>
</div>
</div>
</body>
</html>