I am quite new to Drupal and the whole mySQL and php world so please accept my apologies for my lack of understanding. I am not sure if filing this as an issue is the right for me to raise these questions and whether what I am asking may be more a feature request than a support question.

I have searched and read through a number of posts on Drupal.org and also posted this item in the forum http://drupal.org/node/312383.

On speaking with other local Drupal users I believe the problem is present not just in Drupal 6.x but also prior versions of Drupal. They encouraged me to submit it as in issue or feature request if one didn't already exist. I have looked and don't see one, so here are my details:

In Drupal 6.x the settings Administer>File system allows configuring the location of the files directory and the temp directory. However, if one takes an existing site and moves it to a directory with a different name, configuring the path in the File system setting is not enough to have the site operate fully. One does not see existing customized color changes to the theme, user pictures, images attached to nodes and any other items that also use the files directory or sub-directories therein.

It may be that the paths to these files are embedded within the database as an absolute rather than relative to the File system setting.

It would be nice if it were easy to move a site to a renamed directory and simply change the File system setting.

Is there already any easy way to do this?

What other solutions are there?

Is it necessary to run a mySQL script to change the database?

Or is one compelled to keep the files directory in a fixed location?

I would appreciate any feedback. Thanks,

Izzy

Comments

ainigma32’s picture

Status: Active » Fixed

You should have no problem if you're using the public download method in admin/settings/file-system When you use that setting the paths in the files table are relative.

When you use the private method the paths are absolute and that is probably what happened in your case.

In that case you will have to update the information in the files table with an sql script or do it manually using something like PHMyAdmin.

- Arie

izmeez’s picture

That is interesting. I will have to go back and explore this.

It raises questions as to what happens if I take an existing site and change the setting? Do you know the answer to this? I will have to run some tests.

Thanks,

Izzy

Status: Fixed » Closed (fixed)

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

talino’s picture

Version: 6.4 » 6.13
Status: Closed (fixed) » Closed (won't fix)

I'm having the exact same issue but editing the database directly doesn't fix it for me. Previously all user pictures were set to be in "user-pictures". This was automatically located in sites/default/files/user-pictures. When putting the site online, I enabled the private download method and set the file system path to /home/httpd/vhosts/mydomain.com/my_files/ (which was recognized by Drupal). However, all user picture Only local images are allowed. links now point to http://www.mydoman.com/system/files/sites/default/files/user-pictures/fo... which is obviously wrong. If I change the path in the users table from "sites/default/files/user-pictures/picture-7.jpg" to "user-pictures/picture-7.jpg", the image disappears completely (i.e. it's not a "missing image" problem, rather the img tag is completely absent in the source html).

I should add that Drupal doesn't show an error since in the User Settings, under the Picture Image Path, the help text says: "Subdirectory in the directory /home/httpd/vhosts/mydomain.com/my_files/ where pictures will be stored." And the field has "user-pictures" in it.

I've tried emptying the cache, rebuilding the theme... Please help if you can because the site doesn't go live because of this :)

Thanks.

-- EDIT --

This doesn't concern only the users pictures by ALL files already uploaded (I got a couple of PDFs for testing which exhibit the same behavior). Surely this can be quickly fixed somewhere in the table...

talino’s picture

Status: Closed (won't fix) » Closed (works as designed)

Actually this turns out to be an easy problem to solve. Be warned that I am far from being a MySQL expert. More often I turn my face in horror whenever I see anything that looks like a MySQL query. But this has worked for me and was really easy to do. I just post this in case someone like me wanders around the site looking for answers to this issue.

It turns out that Drupal stores paths to files with a full URL. If you're using Public Download Method with the default path of "sites/default/files", then all your files will have "sites/default/files/filename.ext" as their filepath in the database. It's not just "default path" + "file", it's the whole thing. And this is for every file you ever uploaded, including user pictures and stuff your users put on the site.

When you switch to Private Download Method, your File System Path has to be changed to point to a folder outside your web root. On my shared host, it had to be a folder on the same level in the tree as httpdocs, cgi-bin and the rest of that stuff. I had no permissions to create folders there but when I asked kindly they did it for me. Not only that, their copied my entire "sites/default/files" folder into my root ftp tree. Now it was just a question of Drupal finding the files there.

The Drupal File System Path has to be changed to reflect the full path that points to your folder in your host's folder structure (because they are hosting a ton of sites other than yours). My hoster kindly provides the path by default but you may have to ask yours for the required tree. In my case, it looked like this, "my_files" being the original "sites/default/files" folder which they copied and renamed for me:

/home/httpd/vhosts/mydomain.com/my_files

The alternative syntax, "one folder up", worked on my local testing machine using MAMP but I can't be sure it will work anywhere. YMMV. It looks like this:

../my_files

Either of these strings should go into your File System Path field when you switch to Private Download Method.

Now, because of the way Drupal stores files references (described above), this will not automatically update your URLs, as I've discovered after aimlessly emptying caches, clicking on whatever said "rebuild" etc. You have to change the files references in the database, but like I said this is very easy.

For the user pictures, if you check the "users" table in PHPMyAdmin you'll see all your registered user accounts. One of the fields is called "picture" and is full of strings that start with, you guessed it, "sites/default/files". If you configured Drupal to store user pictures in a specific folder (in the User Settings), a picture might have its filepath set to: "sites/default/files/user-pictures/Picture-4.jpg". What you need to do is run a MySQL command that changes all of these strings to reflect the new path. I figured this out when, after switching to Private Download Method, I uploaded a new file to see where it was landing and what its filepath looked like in the users table. It turns out it looks exactly like this :

/home/httpd/vhosts/mydomain.com/my_files/user-pictures/Picture-17.jpg

So you need to run a command that does a basic search and replace, and it looks like this:

update users set picture = replace(picture,'sites/default/files','/home/httpd/vhosts/mydomain.com/my_files);

What it does is Update the Users table and set the Picture field to a new value based on the value of the argument.

For the rest of your files, if you check the "files" table you'll see something very similar to the above. The command in this case would be:

update files set filepath = replace(filepath,'sites/default/files','/home/httpd/vhosts/mydomain.com/my_files);

I obviously tried this first on a local copy of the database, and so should you. Once I saw the site found its files again, I applied the same to my live site.

BTW, it really helps when you're moving stuff around to have a neat tree structure for your files based on content types, which is something the Upload Path module does very well. It's much easier to move stuff around when you have a structure like files/articles, files/documents etc.

Hope it helps someone somewhere.