I am using an Apache Server which works in localhost. I don't know php so I tried the code from w3schools site but I cannot make it work.
Here is the HTML code :
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
The PHP code :
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
echo $target_file;
$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["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
The echo command in the beginning of the php code, only returns "uploads/" so I guess the $_FILES does not work properly.
EDIT2
I have reinstalled Apache with XAMPP this time and I have no more problem with the code(it outputs "File is an image") but there is still no file uploaded in my "uploads" folder. My "uploads" folder is in the same folder than my web page in localhost.
I am using the default php.ini (file_uploads = on). I tried different files of different size from different directories but no success so far.