Hi,
I have installed PHP8.2 and Apache and uploaded a simple PHP script to upload images. It’s a very simple php script to upload files.
The issue is that I’m getting this message “Failed to open stream: No such file or directory in”. Which means that the temp file was not uploaded to /tmp folder.
The print_r($_FILES) displays this:
Array ( [name] => 14955828_1517805064899902_6497754076576078705_n.jpg [full_path] => 14955828_1517805064899902_6497754076576078705_n.jpg [type] => image/jpeg [tmp_name] => /tmp/phpxuSNXU [error] => 0 [size] => 72072 )
The error result is 0, which means that the file was uploaded. However, when I check the /tmp folder, the uploaded file is not there.
It looks like the file is not even uploaded to the /tmp file.
This is a new fresh installation.
Does anybody experience this before?
Thanks for your help.
FranZ
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!
Heya @e13a2e98219c4801b536a0e92597b9,
I would assume it’s a permissions and ownership issue. I don’t think Apache has the permissions to write to the /tmp file. Try to create a folder where your script is, set it with the Apache ownership and proper permissions and see if that would help.
More often than not when uploads don’t work it is because of permissions and ownership issues. The thing is they do not get logged in your PHP logs.
Hi FranZ,
It sounds like that the upload path is not correctly defined in your script. A simple way to keep track of the path is just to define the absolute path in your PHP app. If this is not the case, would it be possible for you to share your upload script here so I could further review it?
Besides that, there are a few general things that I could suggest checking:
The most common issue with file uploads in PHP is related to permissions. Ensure that the /tmp directory (or whichever directory is specified in your php.ini for upload_tmp_dir) has the correct permissions and ownership. The directory should be writable by the Apache user (usually www-data on Ubuntu). You can adjust permissions using chmod and ownership using chown.
Double-check your php.ini file. Sometimes, the upload_tmp_dir setting is altered, and PHP tries to use a different directory for temporary files. If this directory doesn’t exist or isn’t writable, it could lead to the error you’re seeing. Also, verify the post_max_size and upload_max_filesize settings to ensure they’re large enough to handle the files you’re trying to upload.
Make sure your PHP script uses the move_uploaded_file() function to move the uploaded file from its temporary location to the desired directory. This function not only moves the file but also provides a security check to ensure the file was uploaded via a PHP script. If you’re doing any additional processing or renaming of the file, ensure that those steps are correctly implemented.
Good luck, and I hope this helps!
Best,
Bobby
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.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.