So I am using a raspberry pi and want to use it as a place where I can upload and download any kind of file with any kind of extension.
Here is my html
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="upload">
</form>
</body>
</html>
Here is my php
<?php
if(isset($_FILES['file'])) {
$file = $_FILES['file'];
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
$allowed = array('txt', 'jpg');
if(in_array($file_ext, $allowed)) {
if($file_error === 0) {
if($file_size <= 1073741824) {
$file_name_new = uniqid('', true) . '.' . $file_ext;
$file_destination = 'files/' . $file_name_new;
if(move_uploaded_file($file_tmp, $file_destination)) {
echo $file_destination;
}
}
}
}
}
It works great but only lets me upload .txt and .jpg files. I tried removing the "$allowed" thing all together but broke the script.
Any ideas?