0

I am trying to have file uploading with PHP 7.3 FPM and Nginx but it is not working. What is weird is that on my localhost this works (as long as I change the file upload path and that sort of thing). My phpinfo() says that file uploads are on. My index.php is

<html>
<body>
<form action = "upload.php" method="POST" enctype="mutipart/form-data">
<input type="file" name="file">
<button type="submit" name="submit">Upload</button>
</body>
</html>

The directory it is in is /var/www/html/ and then my upload directory is /var/www/html/uploads/ my upload.php is

<?php
if (isset($_POST["submit"]))  {
    $file = $_FILES["file"];
    $fileName = $_FILES["file"]["name"];
    $upload_folder = "/var/www/html/uploads/";
    move_uploaded_file($_FILES["file"]["tmp_name"], $upload_folder.$_FILES["file"]["name"]);
}

When I put in echo print_r($file) it returns 1. Any idea what is going wrong?

rcwar
  • 1
  • 1

1 Answers1

0

I believe you are uploading file to your "uploads" folder directly under your web folder.

  1. Make sure the uploads folder has been created in the server
  2. Make sure the uploads folder is write-permitted (the files uploaded by php are owned by and comes under the group www-data)
  3. Please use relative path (absolute path may be forbidden (or totally different from your localhost path) in hosting environments). Hence change
$upload_folder = "/var/www/html/uploads/";

to

$upload_folder = "./uploads/";
Ken Lee
  • 6,985
  • 3
  • 10
  • 29
  • Thank you. I forgot to mention that I did enable permissions for my uploads directory. It seems that changing the `$upload_folder` value doesnt do anything. Any other ideas? – rcwar Jul 11 '21 at 16:18
  • How large (in size) is the file you are attempting to upload ? Make sure write permissions apply to web-user say **www-data** . You may see [this](https://stackoverflow.com/questions/8457683/php-move-uploaded-file-fails-and-i-dont-know-why) – Ken Lee Jul 11 '21 at 16:36
  • The files are very small with the main one I am using being 103 kilobytes. As onto the www-data comment, how would I apply that in this use case? – rcwar Jul 11 '21 at 23:38