I'm trying to upload an image to a directory, but there is an issue with the form. When the form is submitted it is redirected to the php file specified in the form action, but then it seems to be unaware of the form being submitted.
HTML
<html>
<form action="profileimg.php" method="post" enctype="multipart/form-data">
<label for="chooseimg" class="profile-pic-change"><i class="material-icons" style="color: rgb(255, 255, 255);">add_a_photo</i></label>
<input type="file" name="image" accept="image/gif, image/jpeg, image/png" id="chooseimg" value="Image" onchange="javascript:this.form.submit();" />
</form>
</html>
(I've also tried using a regular submit button; no difference.)
PHP
<?php
include 'connect.php';
$target_dir = "Users/";
$name = $_FILES["image"]["name"];
$name = md5($name);
$name = $name . uniqid($name);
$path = $_FILES["image"]["name"];
$ext = pathinfo($path, PATHINFO_EXTENSION);
$name = $name.".".$ext;
$target_file = $target_dir . $name;
if(isset($_POST['submit']))
{
move_uploaded_file($_FILES["image"]["tmp_name"], $target_file);
$SQL = "INSERT INTO Users (image) VALUES ('$target_file')";
$result = mysql_query($SQL);
if( $result )
{
echo "<script type='text/javascript'>alert('success!')</script>";
}
else
{
echo "<script type='text/javascript'>alert('failed!')</script>";
}
}
else
{
echo 'didnt submit';
}
?>
I added the didn't submit echo after getting neither of the alerts to see if that was the result, and that is all I get. It redirects to that page and just displays didn't submit. Any thoughts as to why that may be?
Thanks in advance.