I have a php script that I wrote with a lot of help from internet and I do not fully understand what is going on. It is an upload tool which is supposed to send files uploaded to my website in a folder on the server called uploads. It works perfectly well when I use xampp, but when I run it on a remote server, that my university provided me, the script saves the files in its root folder, instead of sending them in the "uploads" folder that I created there.
I tried specifying the directory in different ways, but since it works on my computer and doesn't on the university server I got no idea what to do. The university server works with apache2 and on my computer I used the latest version of xampp for local testing.
index.html and upload.php are in the same folder and there is a subfolder called "uploads" on both of the computers.
<?php
if(isset($_POST['submit'])){
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt=explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('cvs');
if(in_array($fileActualExt, $allowed)) {
if($fileError === 0){
if($fileSize < 100000){
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
header("Location: index.php?uploadsuccess");
} else {
echo "Your file is too big!";
}
} else {
echo "There was an error uploading your file!";
}
} else {
echo "You cannot upload files of this type!";
}
}
?>
I expected the files to be in uploads, but they go in the same folder as the script instead.