Z jakiegoś powodu poniższy kod HTML nie wysyła metodą post pliku do PHP. Metoda isset[$_FILES["fileToUpload"]["name"] zwraca mi wartość false;
<form method="post" action="send.php" enctype="multipart/form-data">
Wybierz plik:
<input type="file" name="fileToUpload" id="fileToUpload">
</br>
<input type="submit" value="submit" name="submit" name="submit">
</form>
<?php
echo $_FILES["fileToUpload"]["name"]; //Już tutaj nie pojawia się nic
$target_dir = "files/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"]) && isset($_FILES['fileToupload'])) {
$file_temp = $_FILES['fileToupload']['tmp_name'];
}
else if(isset($_POST["submit"]) && !isset($_FILES['fileToupload'])) {
print "Form was submitted but file wasn't send";
$uploadOk=0;
}
else {
print "Form wasn't submitted!";
$uploadOk=0;
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>