views:

293

answers:

1

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));

*EDIT: Solved, The issue was that for some reason drupal needed write permissions in the sites/default/files folder to create a .htaccess file.

+3  A: 

The code in file.inc wants to update/create the .htaccess file in the files directory ('sites/default/files' in your case). That it fails could mean that your web server process' do not have write permissions in the files directory at all (unlikely, as this would give more prominent errors in the backend), or that there already exists a .htaccess file in that directory which is set to read only (more likely, could have happened on migration and can easily be overlooked, as the file is hidden by default).

Henrik Opel
Thanks, it was this. Drupal was trying to create a htcaccess file inside sites/default/files
0al0
We get this a lot on our CENTOS / PLESK server. We're continually having to go and either "chown" files to belong to the apache group or give them more relaxed write permissions.
hfidgen

related questions