im relatively new to coding, but nevertheless have got a little problem. My main problem basically is that the file I have chosen to upload doesnt end up in the toimport folder on the Server, altough the function shows a success. Please help if you may know a solution to this problem.
The script from Upload_form.php :
<script>
// Wir registrieren einen EventHandler für unser Input-Element (#uploadFile)
// wenn es sich ändert
$('body').on('change', '#uploadFile', function() {
var data = new FormData(); // das ist unser Daten-Objekt ...
data.append('file', this.files[0]); // ... an die wir unsere Datei anhängen
$.ajax({
url: 'upload.php', // Wohin soll die Datei geschickt werden?
data: data, // Das ist unser Datenobjekt.
type: 'POST', // HTTP-Methode, hier: POST
processData: false,
contentType: false,
// und wenn alles erfolgreich verlaufen ist, schreibe eine Meldung
// in das Response-Div
success: function() { $("#responses").append("Datei erfolgreich hochgeladen");
}
});
});
</script>
upload.php
$target_dir = "toimport/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$FileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Allow certain file formats
if($FileType != "xlsx" && $FileType != "xls" && $FileType != "csv"
&& $FileType != "gif" ) {
echo "Sorry, only XLSX, XLS & CSV 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.";
}
}