Can someone help me understand why this is returning false?
if ((move_uploaded_file($_FILES[$field][\'tmp_name\'], $path))) {
As in, potent
I was facing the same problem.
If your error says "Failed to open stream: Permission Denied" it means the PHP Server is not being capable of creating the new file inside your destination directory.
Once you have set the Linux permissions on the directory (wich sounds like you did by making it 777) you should give that special permission to the PHP Server.
If your folder is named "uploads", you should cd to the previous directory and use the next command:
chcon -R -t httpd_sys_rw_content_t uploads
That definetly solved my problem.
Hope it helps.
Basic debugging steps:
print_r($_FILES)
look like? $path
look like? My guess is that $path
is only a path to a folder, not to a full file name.
Update: You need to specify a filesystem path as $path.
With move_uploaded_file
you don't need 777 permissions. What is the output of $path
? Have you verified that $path
exists? Have you verified that $field
exists?
Either $field or $path don't exist, or open_basedir is in effect is my guess.
Is open_basedir
restriction enabled? That could prevent the destination of the uploaded file from being written to. Look in your php.ini for open_basedir
, if there's a path specified then it is enabled and you want to see if the destination path of your uploaded file is within this path. If it is, that's why it's failing.
update
$path cannot be a URL, it must be a local path such as /home/user/public_html/
Don't use
$path = "http://www.barbadostravelbuddy.co.uk/demo/images/carhire
/accountile10420103260403000000pm.png"
but
$path = "/home/sites/barbadostravelbuddy.co.uk/public_html/demo/images/carhire/
accountile10420103260403000000pm.png"
It needs to be a path on the system, not an URL.
Did you check permission on the temporary upload folder?
What does php tell you if you do:
var_dump($_FILES);
$path
has to be a file name and not a path to a directory.