I am new to PHP and I have been trying to make an image Uploader with PHP, but I have a problem, it only uploads 3 pictures then it stops and I don't know why it is so.
This is the HTML Code
<?php
require ('script.php');
$classObj = new news ;
$classObj->dbcon();
?>
<!DOCTYPE html>
<html>
<head>
<title>test drive</title>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input type="text" name="username" placeholder="username"></input>
<input type="text" name="firstname" placeholder="firstname"></input>
<input type="file" name="file"></input>
<input type="submit" name="submit"></input>
</form>
<?php $classObj->sent(); ?>
</body>
</html
This is the PHP Code
function upload(){
if (isset($_POST['submit'])) {
$this->img_name = $_FILES['img']['name'];
$this->img_size = $_FILES['img']['size'];
$this->img_tmpname = $_FILES['img']['tmp_name'];
$this->img_path = basename($this->img_name);
$this->img_ext = $_FILES['img']['type'];
$this->img_dir = 'upload/'.$this->img_path;
if ($this->img_ext != "jpg" || $this->img_ext != "JPG" ||$this->img_ext != "png" ||$this->img_ext != "PNG" ||$this->img_ext != "JPEG" ||$this->img_ext != "jpeg" ) {
if (file_exists("$this->img_dir")) {
echo "<p> sorry file exist</p>";
exit();
}else{
move_uploaded_file( $this->img_tmpname, $this->img_dir);
echo '<p>succesfull</p>';
echo $_FILES['img']['size'];
header("location:$this->img_dir");
}
}else{
echo "invalid pics";
}
}
}
You have a miss match of name. Change the name of the field to img because you are calling it's value in your PHP script.
<input type="file" name="img"></input>