Hey guys,
I am trying to implement a simple upload form and I am having some issues with the functionality. I found a simple form at W3Schools.com, but when I run it, the file never ends up in the folder that I set-up. I have 2 separate web pages and a "uploads" folder to store the uploaded files . I have already searched online for solutions, but with no luck. My PHP is working fine with no issues. I tried changing the option in my php.ini , "file_uploads" to On, that had little affect. Please any help is appreciated.
Software - Win2012 SE R2, phpmyadmin, IIS8, PHP 7.0.7
First Page (index.html)
<!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>
Second Page (upload.php)
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$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;
}
}
?>
I am trying to implement a simple upload form and I am having some issues with the functionality. I found a simple form at W3Schools.com, but when I run it, the file never ends up in the folder that I set-up. I have 2 separate web pages and a "uploads" folder to store the uploaded files . I have already searched online for solutions, but with no luck. My PHP is working fine with no issues. I tried changing the option in my php.ini , "file_uploads" to On, that had little affect. Please any help is appreciated.
Software - Win2012 SE R2, phpmyadmin, IIS8, PHP 7.0.7
First Page (index.html)
<!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>
Second Page (upload.php)
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$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;
}
}
?>