Error in image upload with PHP [closed]

1

When submitting the form register name, email and password, but the image does not register and I can not find the error.

Some unsuccessful attempts:

  • By putting enctype="multipart/form-data" the file posted to MySQL the temp , but does not put the image to the folder.

Code:

<?php
require('db.php');
// If form submitted, insert values into the database.
if (isset($_REQUEST['username'])){
    $username = stripslashes($_REQUEST['username']); // removes backslashes
    $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
    $email = stripslashes($_REQUEST['email']);
    $email = mysqli_real_escape_string($con,$email);
    $password = stripslashes($_REQUEST['password']);
    $password = mysqli_real_escape_string($con,$password);

    $picture    = $_FILES['foto']['tmp_name'];
    $img_name = $_FILES['foto']['name'];
    $dir      = "/var/www/uploads/";
    $path     = $dir.$img_name;
    move_uploaded_file( $picture, $path );  

    $date = date("Y-m-d H:i:s");

    $query = "INSERT into 'users' (username, password, email, picture, date) VALUES ('$username', '".md5($password)."', '$email', '$picture' ,'$date')";
    $result = mysqli_query($con,$query);
    if($result){
        echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
    }
}else{
?>

My form

 <form name="registration" action="" method="post">
 Upload Imagen : <input type="file" name="foto" />
 <input type="text" name="username" placeholder="Username" required />
 <input type="email" name="email" placeholder="Email" required />
 <input type="password" name="password" placeholder="Password" required />
 <input type="submit" name="submit" value="Register" />
  </form>

My table in the bank:

  CREATE TABLE 'users' (
  'id' int(11) NOT NULL,
  'username' varchar(50) NOT NULL,
  'email' varchar(50) NOT NULL,
  'password' varchar(50) NOT NULL,
  'picture' varchar(100) NOT NULL,
  'level' tinyint(1) NOT NULL DEFAULT '0',
   'ative' tinyint(1) NOT NULL DEFAULT '0',
   'date' datetime NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 
    
asked by anonymous 07.07.2017 / 23:19

0 answers