CCK 6.x-2.2
imagefield 6.x-3.0-alpha4

I've got nodes using a CCK ImageField. UserA creates a node, and I, the admin, would like to add an image to that node. The current path is set to be "project_pics/[user]". You would think this would insert the node's author's name, but it doesn't. Instead, it inserts the admin's username. This is a problem.

For example, when I, Admin, add images to UserA's nodes, the path to those images gets set to "project_pics/admin/filename.jpg" instead of "project_pics/UserA/filename.jpg"

1) How do I add the node's author's name to the path.
2) How do I go back and change ImageField images to link to the node's author's folder instead of the admin (i.e. how do I change the path to images)? I added a ton of images before I discovered this problem :(

Thanks.

Comments

quicksketch’s picture

Use the FileField Paths module to gain access to the node-level tokens, then use the [author-name] token instead. The [user] token always means the currently logged in user. You'll need to upgrade to the latest version of ImageField and FileField.

2) How do I go back and change ImageField images to link to the node's author's folder instead of the admin (i.e. how do I change the path to images)?

I'd recommend a PHP script of some sort. Use the file_move() function to move the files and db_query() to update the paths.

quicksketch’s picture

Category: bug » support
gallamine’s picture

Thanks! Any tips on what db_query() I should be running to update the paths?

quicksketch’s picture

Probably something like this (not tested at all).

$result = db_query("SELECT * FROM {content_whatever_table} c INNER JOIN {files} f ON c.fid = f.fid");
while ($row = db_fetch_object($result)) {
  $newpath = str_replace('old', 'new', $row->filepath);
  file_move($row->filepath, $newpath);
  db_query("UPDATE {files} SET filepath = '%s' WHERE fid = %d", $newpath, $row->fid);
}
quicksketch’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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