I trying to create an apache2 webpage that allows user upload nifti(.nii, .nii.gz) files.
I tried two different ways:
On WSL Ubuntu 18.04, "move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)" returns nothing. Its totally fails.
On XAMPP, the page can take files such as PDF, JPG ..etc, but not .nii, .exe (I checked $_FILES['file']['tmp_name']; is empty)
HTML:
<form action="upload.php" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="file">
<input class="" type="submit" value="Upload" name="submit">
</form>
php:
$target_dir = "/home/user/public_html/uploads/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$file_tmp =$_FILES['file']['tmp_name'];
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
echo "<br>";
} else {
$moving = move_uploaded_file($file_tmp, $target_file);
echo $moving;
echo "here <br>";
if ($moving) {
echo "The file ". basename( $_FILES["file"]["name"]). " has been
uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
- Did someone uploaded file successfully on a WSL apache2?
- Why I can't upload files like ".nii", ".nii.gz", ".exe"?
Thank you for reading!