We have a content type with two imagefield / filefield fields, and after migrating our site to a new server, we have the following problem:

When we submit a new item for this content type, with two images for those fields, drupal gives us the following error and does not upload the images:

warning: fopen(sites/default/files/.htaccess) [function.fopen]: failed to open stream: Permission denied in /websites/sitename/data/sites/all/modules/filefield/field_file.inc on line 349. warning: fopen(sites/default/files/.htaccess) [function.fopen]: failed to open stream: Permission denied in /websites/sitename/data/sites/all/modules/filefield/field_file.inc on line 349. An image thumbnail was not able to be created. warning: fopen(sites/default/files/.htaccess) [function.fopen]: failed to open stream: Permission denied in /websites/sitename/data/sites/all/modules/filefield/field_file.inc on line 349. warning: fopen(sites/default/files/.htaccess) [function.fopen]: failed to open stream: Permission denied in /websites/sitename/data/sites/all/modules/filefield/field_file.inc on line 349. An image thumbnail was not able to be created.

I understand this is a permissions error, but it is not clear to me where do I have to change permissions. Line 349 of file.inc has the following code:

if (($fp = fopen("$directory/.htaccess", 'w')) && fputs($fp, $htaccess_lines)) { fclose($fp); chmod($directory .'/.htaccess', 0664); } else { $repl = array('%directory' => $directory, '!htaccess' => nl2br(check_plain($htaccess_lines))); form_set_error($form_item, t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines:
!htaccess", $repl));

Comments

quicksketch’s picture

It sounds like Drupal is unable to create the ".htaccess" file within your files directory that is needed for security reasons. You need to SSH or FTP into your server and set the permissions on the files directory so that Drupal can create this file. What permissions you use depend on how your server is configured. Typically the files directory is chmod 775 (read/write/execute for owner and group, read/execute for others). You can use any one of the thousands of references on how to chmod files to accomplish this.

oalo’s picture

That worked! Thanks a lot quicksketch, I owe you a beer. But I dont understand, arent htaccess files apache configuration files in the root of the virtual server? Why does drupal need to create an extra htaccess file in the files folder?

oalo’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.