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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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 yourphp.ini
forupload_tmp_dir
) has the correct permissions and ownership. The directory should be writable by the Apache user (usuallywww-data
on Ubuntu). You can adjust permissions usingchmod
and ownership usingchown
.Double-check your
php.ini
file. Sometimes, theupload_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 thepost_max_size
andupload_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
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.