search

Home  >  Q&A  >  body text

Title rewritten as: Uploaded files cannot be moved when permissions are insufficient

I have a PHP script through which I can upload a file and am trying to move it from /tmp to test/ (relative path, located in my project folder, e.g. /var/www/html/myproject/test will be an absolute path). When this happens I get the following error.

move_uploaded_file(test/test.csv): Unable to open stream: Permission denied at /var/www/html/myproject/import.php, line /import2.php

This script is run by the apache user, who has ownership of /test (both the apache owner and the apache group own this directory) and has rwx permissions.

I have checked the following:

P粉210405394P粉210405394531 days ago599

reply all(1)I'll reply

  • P粉564192131

    P粉5641921312023-09-08 09:41:48

    move_uploaded_file requires two parameters. 1: The file you want to upload 2: Place the absolute path of the file 3: Please make sure that the upload directory has appropriate ownership and permissions (Note: If you are using Apache as a proxy, the directory ownership should belong to the user: group of apache2).

    示例:move_uploaded_file($_FILES['my_file_field_name']['tmp_name'], "/var/www/html/myproject/test/upload_dir/" . $_FILES['name']['tmp_name']);

    Read more: https://www.php.net/manual/pt_BR/function.move-uploaded-file.php

    reply
    0
  • Cancelreply