Software⏱️ 2 min read📅 2026-05-31

How to Fix: move_uploaded_file gives "failed to open stream: Permission denied" error

PHP upload file permission error fix

Quick Answer: Check the directory permissions for /var/www/html/mysite/tmp_file_upload/ and ensure that the web server (Apache) has write access to this directory.

The error 'move_uploaded_file gives "failed to open stream: Permission denied"' occurs when the PHP script trying to upload a file fails due to insufficient permissions. In this scenario, the issue lies with the Apache configuration and directory permissions.

⚠️ Common Causes

  • The upload_tmp_dir directory does not have the correct permissions.

🛠️ Step-by-Step Verified Fixes

Method 1: Adjusting Permissions

  1. Step 1: Change the ownership of the upload_tmp_dir directory to the web server user using the command `chown -R apache:apache /var/www/html/mysite/tmp_file_upload/`.

Method 2: Changing Directory Permissions

  1. Step 1: Change the directory permissions of the upload_tmp_dir to make it writable by the web server user using the command `chmod -R 755 /var/www/html/mysite/tmp_file_upload/`.

🎯 Final Words

To resolve the 'move_uploaded_file' error, ensure that the upload_tmp_dir directory has the correct permissions and ownership. By following these steps, you should be able to fix the issue and successfully configure file uploads with Apache 2.2 and PHP 5.3 on CentOS.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions