How to Fix: move_uploaded_file gives "failed to open stream: Permission denied" error
PHP upload file permission error fix
📋 Table of Contents
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
- 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
- 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.
❓ Frequently Asked Questions
🛠️ Related Fixes
How to Fix: Pc crashes shortly after launching game (rainbow
Pc crashes shortly after launching game, possible cause: outdated grap
How to Fix: Installing an APK on a locked down phone
Installing an APK on a locked down phone: Try using a rooted device, e
How to Fix: FPS drops
FPS drops in games can be caused by high system resource usage, outdat