Upload Files to Upload Directory Permissions Issue

Permalink 2 users found helpful
I have set all of my permissions to 777 within "FILES", (recursive) but for some reason I still can't upload any images to the file manager. I get the following error.

Unable to copy file to storage directory. Please check permissions on your upload directory and ensure they can be written to by your web server.

Is there another directory that I need to change the permissions on? If so, can someone give me the path to it?

Thank you

View Replies: View Best Answer
nteaviation replied on at Permalink Reply
I would try resetting the 777 recursive permissions again. Also, the file directory should be "/files" not "/FILES". Do you have two /files directories?
anthonywest replied on at Permalink Reply
I have done the reset to 777 twice now. It is /files. I just put the previous in all caps. Any suggestions?
nteaviation replied on at Permalink Reply
Have you looked in the /files directory and made sure everything in there is 777?
nteaviation replied on at Permalink Reply
You could also check your php.ini (i like to use phpinfo.php), looking at directives:

anthonywest replied on at Permalink Reply
Here is what my php.ini file currently says.

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir = tmp

; Maximum allowed size for uploaded files.
upload_max_filesize = 9M
nteaviation replied on at Permalink Reply
This looks ok, as long as you don't upload any images bigger than 9M :)
anthonywest replied on at Permalink Reply
Yes as far as I could. I have hundreds of images within that directory. Is there a code somewhere that needs to be changed? Should I be able to set these permissions within the dashboard? I don't see anywhere that allows those settings.
nteaviation replied on at Permalink Reply
Did file-upload just stop working all of a sudden or did it ever work?
anthonywest replied on at Permalink Reply
It worked before I moved my site to another server.
nteaviation replied on at Permalink Reply
Ah, ok. So we just have to figure out what is different with this server. Have you cleared the site cache? Just a shot in the dark.
anthonywest replied on at Permalink Reply
How do I clear the site cache? I know how to do that within my PC browser, but not on my site.
nteaviation replied on at Permalink Reply
In the Dashboard, Sitewide Settings, Debug tab, Cache, Clear Cache.
anthonywest replied on at Permalink Reply
I have cleared the cache and it is still not working. How do I get to the read/write permissions within the dashboard?
nteaviation replied on at Permalink Reply
All the file permissions are controlled by the operating system.

Are you trying to upload files via the Dashboard file manager or via something else, like Gallery?

Is the /packages directory set to 777 recursively?
anthonywest replied on at Permalink Reply
Trying to upload through the dashboard file manager. I also just set the /packages directory to 777 recursively, and it still doesn't work.
anthonywest replied on at Permalink Reply
I was told to issue the following command in the c5 directory.

chmod -r 777 files

However there is nothing in the c5 directory currently to edit. How do I go about issuing this command?
nteaviation replied on at Permalink Reply
Unless you have SSH or local access to your box, you can not execute a chmod command. What FTP client are you using? You can use FileZilla, an excellent and free FTP client that will allow you to change permissions on directories/files your account.
anthonywest replied on at Permalink Reply
I am using FileZilla. I do have ssh access. How do I execute the command from there?
nteaviation replied on at Permalink Reply
It would be easier to do with FileZilla. Find the files folder and right click on it, and select "File Permissions". Enter 777 in numeric value.Check the Recursive box. Hit OK.

Do the same for the packages folder.

I hope it works :)
anthonywest replied on at Permalink Reply
Wow, after all of this, I went into my server and saw that PHP safe mode was turned on. Once I turned it off, I can now upload files. Thanks for steering me in the right direction.

nteaviation replied on at Permalink Reply
Fantastic, congratulations! Good catch :) I use a little file called phpinfo.php that contains <?php phpinfo() ?> in my webroot. I access it by hitting it with my browser at something likehttp://mysite.com/phpinfo.php. It makes PHP configuration settings easy to see. That may have saved us some time :)
pixelfish replied on at Permalink Reply
Im having the same problems with uploading files.

Safe mode is off, file permissions are all set ok. i have checked everything mentioned above.

the only thing i can see in my phpinfo is that upload_tmp_dir has no value?

i have a dedicated fashosts linux server. anyone elese had similar problems moving a site to a new server?
nteaviation replied on at Permalink Reply
I would try this. Get phpinfo's from both machines and compare the two looking for differneces. This may give us a clue. If it works one place, it should work in the other using the same configs :)
lshcloud replied on at Permalink Reply
Hi There,

I'm having the same issue with my Fasthosts Linux server. PHP Safe Mode is off and also files directory is set to 777 and I cleared sit cache. Did you manage to fix this problem in the end?

lshcloud replied on at Permalink Reply
I managed to fix this by changign the path in the temp folder path in theC5 control pannel. Althoug it had the server path eg /etc/www and so on, when I removed all of this and just put in /files then it worked. Very strange but at least it's working!
Veronikan replied on at Permalink Reply
^^ I wish I had access, I can't change it.

I have checked all user and file permissions, as far as I can tell, all are properly set.

PHP Safe Mode is a different issue, below is what I got from my client's host who discourages turning off safe mode. I believe their requirements are met as well. Regardless, still cannot write to files directory, and I'm also getting cannot write on the site map XML which I find impossible to comprehend, as its permissions are fine also.

The rules for writing files in PHP Fast mode (i.e. with safe_mode enabled) are very simple:

1. The permissions of the file (and/or its parent directory, especially when creating the file) must allow the operation.
2. The file being written and the top-level PHP script being called must be owned by the same user, the same group, or both.

Corresponding to these rules, there are two main steps to follow to set up successful file writing:

1. Set the parent directory you will be writing files in to group web with 775 permissions.
2. Set the top-level PHP script doing the writing to group web with 644 permissions.

By taking these two steps, you will ensure that the destination is writeable and that both the source (the PHP script) and the destination (the file/directory) share the "web" group, thus satisfying both rules. This is the most reliable and secure approach.

The biggest problem people encounter implementing these steps is usually identifying the PHP script that needs to be set to group web. Some people resolve this by simply changing all their PHP scripts to be owned by group web. This approach can work, but requires that more care be paid to file permissions to avoid security issues. We prefer to chgrp only the scripts that actually write files.

It can be counterintuitive that the PHP file that needs to be owned by the web group is the top-level one, not necessarily the one that has the actual file-writing commands. (And, more to the point, often not the one that shows up in a safe_mode-related error message.) If you have access to it, the PHP $_SERVER['SCRIPT_FILENAME'] variable can tell you what the top-level script is. If not (for example for a third-party app like Wordpress or Drupal), your site's access log or error log can usually help you identify it. For popular apps, you can also ask in our forums or check our member wiki for more info on what scripts to chgrp.

We urge people to avoid the urge to both chgrp everything and to set the permissions of everything as group-writeable. (Some apps require/recommend this type of setup in order to allow them to auto-update themselves via the web; doing so trades security for ease of use and is a practice we discourage.) PHP's security track record is not very good, and our system security is designed primarily to protect sites from each other; it does not (cannot) protect sites from themselves. So while "write everything" may work initially, and it seems "easiest," sooner or later a flaw will be found in your site's PHP code or in PHP itself, and if your site is full of group-web writeable files, hackers will make short work of it. Please keep in mind the old adage, "If you don't have time to do it right, how will you have time to do it over?"

Therefore, the final rule of thumb for writing files in PHP is not to set anything to be both owned by group web and group-writeable unless you don't mind restoring it from backup after hackers get to it. We hope this encourages you to both be conservative in what you allow PHP to write, and to keep good backups. :-)
jsunico replied on at Permalink Reply
This worked for me. I have copied my database from a dev server and didn't know that we have this setting in C5 that's why it's pointed to a different directory.
cfh replied on at Permalink Reply
Yes, if you turned "php safe_mode off" and (also open base_dir none); the problem with file upload will be resolved.

In addition to this, i want to add that, if you are using plesk, cpanel or another panel software in your dedicated server; you have to change these values (safe mode and open base_dir) to "off" in panel software's configuration file.

(For example, if you are using plesk panel; you have to change "zz010_psa_httpd.conf" instead of httpd.conf or php.ini )
brian30 replied on at Permalink Reply
If you moved the site go to File Manager, Access, File Storage,,,change your path.
seldinCO replied on at Permalink Reply
Thank you for the great tip. Work perfectly for my issue.
hypnotoad replied on at Permalink Reply
I just moved a c5 site to a new VPS host and afterward the files directory's permissions were corrupted. The only way I could add a new file in the file browser was to set the files directory to 777 perms (recursive).
Is having that dir and its contents set to 777 hazardous/dangerous for any reason?
nteaviation replied on at Permalink Reply
It is a security risk, but how great a securitly risk depends on many different factors. There are so many different ways to configure OS/Web Server/PHP/c5, optimum security has to be done practically on a "case by case" basis". My best advice is to look to subject matter experts on your specific web host. Sorry there is no "simple" answer :(
rblack79 replied on at Permalink Reply
Read through this entire thread and found that the solution is simple so log in as your php.ini is correct. That is to ensure you default file storage location in file manager>Access is set to the full path for files. You do not I repeat do NOT need 777 permissions and should never set those on a directory opened to the web
blakeage replied on at Permalink Best Answer Reply
chown -R www-data files/

Worked for us.
DtotheOR replied on at Permalink Reply
Can you explain your method with more detail? I would like to not have to set 777 permissions.
balods replied on at Permalink Reply
Clearing the cache files works for me.