The image settings page refuses to save a file path, declaring "directory does not exist" even though the directory does exist and all its permissions are correct.

It also gives this message instead of creating a new directory, even though Drupal has the permissions to create a new directory in the files system path.

I think a trigger of this problem is having files and images directories other than in the default files directory– in our case, using sites/example.com/files.

(This is certainly not the only trigger, as all of our sites are set up this way, but it's the only thing I've got.)

Using image-5.x-1.4.

I confirm (hey, 3 a.m., I was feeling literary) the behavior described by a few people on http://drupal.org/node/148601">this thread, and the fix provided by NancyW:

http://drupal.org/node/148601#comment-238058

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drewish’s picture

NancyW's fix is for the user.module, not the image.module... I'm not sure how the two relate?

mlncn’s picture

That's a point.

I (and others on that thread) confirm the same behavior (not saving the images path and giving a false message) for the image module alone, and the fix is analogous:

Go into the database and change the path to what the image module is refusing to save. (image_default_path, not the user picture path from Nancy's example.)

Then everything works.

So the image module (maybe also the user module unless its relying on the image module for user picture paths) is providing a false failure-- saying a path does not exist and cannot be saved when it does exist.

I do not know what triggers this bug, but as a starting point we're using a multisite install with "sites/example.com/files" as the files path for a given site, and an "images" directory inside that.

berenddeboer’s picture

I had to do something different. Looking at the source it appears that the image module needs two variables: file_directory_path and files. Both should have valid paths. Check with select * from {variable} where name = 'files' for example.

In my case the files value pointed to something that did not exist. After creating that, the image module worked.

kpm’s picture

Same problem here, but I think I know what caused it in my case... I mistakenly changed the file system path from
site/example.com/files to just files because I saw the multiple site set up left the urls looking awkward by repeating the example.com... it was late, I was tired... Anyway, after I did this I realized I had broken the site (and then read the fine print under the setting which says not to change this setting on an existing site unless you know what you are doing... sigh). So I tried to fix by changing image file path, no luck then I just tried to revert back to the original file system settings. This worked for the file system setting, but not for the image directory. I get "The directory does not exist" even though it does and is full of images and was working prior to my changes. Now how to fix that...

Hetta’s picture

marked http://drupal.org/node/174305 as duplicate.
marked http://drupal.org/node/210220 as duplicate.

enkara’s picture

What if I don't have such image_default_path in the variable table? This is all very confusing... Can I ask my server administrators to create the folder for me?

Thank you very much

chrislynch’s picture

I had the problem, relating to the setting of file_directory_temp in {variables} after moving from my local dev' environment up to the server.

My quick and easy fix was to go into the filesystem configuration of Drupal and resave the parameters. All working now :-D

SKrossa’s picture

I had this problem, but just changing the image_default_path in the variables table in the database was not enough to fix the problem. So I went (within Drupal) to Administer -> Site configuration -> File system and clicked on "Save configuration". Then I went to Administer -> Site configuration -> Image. Despite having changed image_default_path in the database, the "Default image path" field was now empty (and I got a message about "temp" being created), however, when I entered "images" into the field and saved, it worked, and everything seems to be okay now.

Lappie’s picture

Worked for me (although it may required a real hard reload of the pages).

bhagg’s picture

Version: 5.x-1.4 » 6.x-1.0-alpha1

I am running 6.4 with the same problem and have been searching for hours and trying different solutions with no luck. I would like to try this. How do i change the variable tables in the database?
I am using siteground hosting with a cpanel interface

craigdurling’s picture

Version: 6.x-1.0-alpha1 » 5.x-1.9

I uninstalled image.module, erased the files/images and files/images/temp folders using SSH and then re-created them on my own. When I reinstalled image.module it all worked.

bhagg’s picture

After struggleing with this module for some time this seems to have fixed this issue. I would add that setting up the file directories and giving them 777 permisions before installing the image module is the key. I hope that this helps others with this issue and from the various threads I know there's alot.

yurtboy’s picture

I did the
full remove
remove directory
create dir
chmod 777 / www-data

reinstall
And it all worked BUT
Then I linked the Image node to a taxonomy (multi select) and again the same problem.
I removed the taxonomy and it all worked.
Also note that the Image Gallery part I did not install on the 2nd and 3rd try just cause I did not need it so now it works with the taxonomy module not be used for this node type.

gavacho’s picture

I have the same problem.

I am trying to configure the image import module so that I can add images to a gallery. I get an error message saying that the image import directory doesn't exist. I tried paths to several directories that do exist. I tried absolute paths, paths relative to the document root, and paths relative to drupal. Nothing made the error go away. I am sure that the directories exist, because I can look at them in FTP. I checked the import module code, and it already incorporates the patch mentioned on drupal.org/node/131508.

Judging from this line of code in the patch

#default_value' => variable_get('image_import_path', file_directory_path() .'/images/import')

it appears that there should be /images/import underneath the image_import directory. I created those subfolders in that location but it still doesn't work.

yakker’s picture

I found a solution to my version of this problem buried in this thread: http://drupal.org/node/148601

This is for the few of you who, like me, could find nothing about this in the forums or documentation, but who are on the cutting edge of your own skills every time you manually type "<?php..." or click the pencil icon in PHPMyAdmin. ;)

Solving this, in my case, involved going into the Variables table in the drupal database through PHPMyAdmin.
I looked to verify two variables:

1. file_directory_path,
2. image_default_path.

Make sure the first variable is correct - it refers to your base path to your "files" directory. On my default installation (Drupal 6.6), file_directory_path=s:19:"sites/default/files"
The s:19 part refers to (I think), string of 19 characters. And it turns out, wonder of wonders, that "sites/default/files" is exactly 19 characters with backslashes.

Secondly, image_default_path should correspond to where your images folder is. Mine sat in sites/default/files/images/. But since file_directory_path already takes care of "sites/default/files", my image_default_path variable should just be "images," or more accurately, image_default_path=s:6:"images"

Mine was not, and I had to change it manually. Once I did, cleared the cache (Admin>>Site Building>>Performance), everything's groovey.

Thanks so much to NancyDru!

foripepe’s picture

I have the same problem: "The directory does not exist."
My Image module version is: 6.x-1.0-alpha3.

Reproducible:
Write '../dddddd' in the 'Default image path'. Save the configuration.
After that you will alway see the "The directory does not exist." error message. You can't modify the path.

Solution:
Image.module
There are the _image_check_settings() function.
Change the code from this:

  if (!file_check_directory($image_path, FILE_CREATE_DIRECTORY, 'image_default_path')) {
    return false;
  }
  if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY, 'image_default_path')) {
    return false;
  }

To this:

  if (!file_check_directory($image_path, FILE_CREATE_DIRECTORY, 'image_default_path')) {
    variable_set('image_default_path', 'images');
    return false;
  }
  if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY, 'image_default_path')) {
    variable_set('image_default_path', 'images');
    return false;
  }

It puts back the good value.

Anonymous’s picture

Great! This solved my problem. I was looking at that when I found your post, just don't know php, but I was certain it was that peace of code that had the problem.

Dial8’s picture

Wow, I have been RACKING MY BRAIN over this thing... and there are about 1000 different threads worth of people with the same problem, but simply opening up the image.module file and changing out that code with the lines that foripepe suggested above worked flawlessly... I of course had to create a folder to point to... which i had been doing all along but it didn't actually take until I switched out that code in the image.module php file.

Thank you! --- foripepe should probably send a note to whoever developed this particular module to change out those lines of code so that others don't experience the same problems in the future.

cheers.

dwelch’s picture

I have Image version 6.x-1.0-alpha4

I'm having a very similar problem with the Import Path of the Image Import section of the Images module: "The directory does not exist."

I tried foripepe's solution and noticed that the code in images.module was slightly different from his example. Here's what I saw:

if (!file_check_directory($image_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, 'image_default_path')) {
return false;
}
if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, 'image_default_path')) {
return false;
}

I went ahead and replaced the code anyway, but that didn't have any effect. So I reverted to the original image.module file.

Then I looked at the other solution involving modifying the variables table of the database (best described by yakker) and noticed that the variable image_default_path didn't exist.

After verifying that the file_directory_path variable was set the same as yakker's example, I inserted a record for image_default_path with the value s:6:"images" (just as yakker's example indicates).

This, however, didn't solve the issue of the Image Import Path generating the error "The directory does not exist."

Feeling tired, and knowing that the site I'm working with is not in production, I experimented with adding a variable image_import_path with the same value as image_default_path and that didn't work either.

At this point, I can create image nodes, but I cannot include images inline with pages. Not the end of the world, but annoying to be sure. If anyone has a suggestion, I would appreciate anything you would be willing to contribute.

dwelch’s picture

You know what's really frustrating? Writing a post, as I did above, then finding the answer in the next thread I tried ;)

Here's the answer to the image import issue I described: http://drupal.org/node/366138

foripepe’s picture

dwelch:

  if (!file_check_directory($image_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, 'image_default_path')) {
    variable_set('image_default_path', 'images');
    return false;
  }
  if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, 'image_default_path')) {
    variable_set('image_default_path', 'images');
    return false;
  }

It is working for me. Buy we have to submit the good values two times (admin/settings/image).

foripepe’s picture

PS. Image.module, _image_check_settings() function.

joachim’s picture

I've found the problem with this while messing with token support :)

The path is checked on form *construction*. So the OLD value is being looked at, not the value you have just entered and are trying to save.
So basically, if you put in a bad value (bad characters, for example), you are then PERMANENTLY stuck, as you can't save the form with a good value.
Meanwhile, there is NO path validation in the form when you submit it!

This is totally backwards, in other words :)

Some refactoring of the form code and _image_check_settings() is required.

sun’s picture

Version: 5.x-1.9 » 6.x-1.0-alpha4

I'm not sure why it is done this way. Obviously, the configuration should be verified in the form validation handler. I fear that there is a hidden, undocumented reasoning.

I really hope that drewish or walkah can shed some light in here.

joachim’s picture

Just spoken to drewish in IRC who reckons it's leftover code from the pre-FAPI days of 4.7.

In other words, we can go ahead and get some validation code into that form for the path, and also look at tidying up _image_check_settings().

blagrone’s picture

After scratching my head for about half a day, uninstalling, re-installing ad nauseum and then reading the posts, I figured I'd give the module the path it wanted, and it worked.
The rejected path of my images was /sites/all/images.
The path for my files was /sites/default/files.
So I created these files via ftp /sites/all/images inside the files folder.
So I had /sites/default/files/sites/all/images and the module accepted it.
Then I changed the images path to "images"

Kind of a low-tech fix, but it worked for me.

joachim’s picture

Some questions about how best to do this...

Here is the code we're concerned with in _image_check_settings:

  // File paths
  $image_path = file_create_path(file_directory_path() .'/'. variable_get('image_default_path', 'images'));
  $temp_path = $image_path .'/temp';

  if (!file_check_directory($image_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, 'image_default_path')) {
    return false;
  }
  if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, 'image_default_path')) {
    return false;
  }

Obviously, we need to move the directory checking and creating to the admin form validation.
Q1: What about the case when a user starts to create image nodes without having gone to the admin form?
Q2: file_create_path and file_check_directory can't handle more than one level of path that doesn't yet exist. In other words, if the admin user sets the path to "my/images/go/here" then it all fails. There is a feature request here #270443: Native recursive create directory function. Do we work around this for now the same way CCK does?

freescholar’s picture

CLEARING THE SITE CACHE DID IT!!!

I tried everything listed in this thread and nothing worked until I changed the path to just "images" and then cleared the site cache:
Site Configuration > Performance > Clear Cached Data

Woo Hoo!!!
Thanks to everyone on this thread!!!!!!!!

Now I feel the Drupal love:)

borgvall’s picture

yakker that did the trick.

Note that image import still wants the whole path sites/default/files/images/temp

borgvall’s picture

However the galleries doesn't show up when importing images anymore. Now I don't know how to tell them in which gallery they should end up.

joachim’s picture

Status: Active » Closed (fixed)

Closing; the code tidying up can happen at #543890: ruthlessly kill _image_check_settings().

sun’s picture

Status: Closed (fixed) » Closed (duplicate)

Proper status.

joachim’s picture

Status: Closed (duplicate) » Needs review
FileSize
1.97 KB

In light of the timescale I'm rethinking this, and considering this as a bug to be fixed, and #543890: ruthlessly kill _image_check_settings() as a 'nice to tidy up sometime'.

Here's a patch.

joachim’s picture

I'm not entirely sure about creating the directories in the validation rather than the submit - but how can we check it's possible to create the dirs without creating them?

joachim’s picture

Status: Needs review » Fixed
FileSize
3.14 KB

Had a chat with sun on the way to lunch -- we both reckon it's got to be done in validation so we can set a form error.

Committing the attached patch in order to get a release out today.

Since we now have a regular validation handler for the admin settings form, I'm folding in the settings validation.

One thing I could do with help on is that I can't actually get the directory checking to fail -- could people give me examples of BAD directories please? I've tried things like '/bad' or '../../bad' and I get a form error 'The directory does not exist', which as far as I can tell is not coming from image module!

Anyway -- commit, release, may need to tidy this up on Saturday.

sun’s picture

Thanks!

+++ image.admin.inc	2 Sep 2009 12:55:42 -0000
@@ -5,8 +5,6 @@
-  _image_check_settings();

Isn't _image_check_settings() invoked also from elsewhere? What happened to that function now?

+++ image.admin.inc	2 Sep 2009 12:55:42 -0000
@@ -109,17 +106,30 @@ function image_admin_settings() {
+    
...
+    form_set_error('image_default_path', t('You have specified an invalid directory.'));    
+  }  

Trailing white-space here.

I'm on crack. Are you, too?

joachim’s picture

_image_check_settings() needs a tidy-up as I'm not sure what it's meant to be doing any more or if it's useful.
In fact, I think the only thing it serves for is the following case:
1. install Drupal, but don't visit the files admin
2. install image
3. go to create an image
4. because there is no /files folder yet, the image is created in site root /image !!!
Though we could say this is a bug in core ;)

Status: Fixed » Closed (fixed)

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

hokuspokus’s picture

Using #7 advice worked for me as well.

andrebonfanti’s picture

Using #12 suggestion: setting "file" folder (/sites/default/files/) to 777, and it works for me.
I have not applied code correction or disabled module.

mila5405’s picture

Status: Closed (fixed) » Active

Administer-->Imageimport
Filesimport path: sites/default/files/images/temp
Tried this WORKED

joachim’s picture

Status: Active » Closed (fixed)

I don't think the original bug was about image import.

If you have a bug, file a new issue; if you want to share a tip, add it to one of the handbook pages.

pedjuama’s picture

I'm using Drupal 7 and i have same problem with Picture directory in admin/config/people/accounts. Drupal says "The directory public://users/[current-user:name] does not exist or is not writable." but they don't leave me change this directory.

I don't found 'image_default_path' and i need to solve this. Please help me!