By dufra
I have a droplet and a website in /var/www/html/
index.html:
<!DOCTYPE html> <html lang=“en”> <head> <meta charset=“UTF-8”> <title>PHP File Upload</title> </head> <body> <form action=“fileUploadScript.php” method=“post” enctype=“multipart/form-data”> Upload a File: <input type=“file” name=“the_file” id=“fileToUpload”> <input type=“submit” name=“submit” value=“Start Upload”> </form> </body> </html>
and fileUploadScript.php:
<?php $currentDirectory = getcwd(); $uploadDirectory = “/uploads/”;
$errors = []; // Store errors here $fileExtensionsAllowed = ['ttf']; // These will be the only file extensions allowed $fileName = $_FILES['the_file']['name']; $fileSize = $_FILES['the_file']['size']; $fileTmpName = $_FILES['the_file']['tmp_name']; $fileType = $_FILES['the_file']['type']; $fileExtension = strtolower(end(explode('.',$fileName))); $uploadPath = $currentDirectory . $uploadDirectory . basename($fileName); if (isset($_POST['submit'])) { if (! in_array($fileExtension,$fileExtensionsAllowed)) { $errors[] = "This file extension is not allowed. Please upload a .ttf file"; } if ($fileSize > 16000000) { $errors[] = "File exceeds maximum size (16MB)"; } if (empty($errors)) { $didUpload = move_uploaded_file($fileTmpName, $uploadPath); if ($didUpload) { echo "The file " . basename($fileName) . " has been uploaded"; } else { echo "An error occurred. Please contact the administrator."; } } else { foreach ($errors as $error) { echo $error . "These are the errors" . "\n"; } } }?>
so when someone visits my website he can upload a file on my webserver (droplet) but and error appears “405 Not Allowed nginx/1.18.0 (Ubuntu)”. How can I fix this???
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
The 405 Method Not Allowed error occurs when the web server is configured in a way that does not allow you to perform a specific action for a particular URL. It’s an HTTP response status code that indicates that the request method is known by the server but is not supported by the target resource
Can you please provide us with the Nginx configuration you are using as you’ll need to configure this there?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
