I see the webform can set a directory to upload files to under /files/webform/....

Is there a way to set it to upload files to a directory outside of the 'webform' directory? e.g. /files/directoryA/ or /files/directoryB/?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Not currently. Webform keeps all files uploaded inside the "[files]/webform" directory.

startechglobal’s picture

is there anyway to upload to a dynamically named directory such as /files/webform/xxusernamexx/ ?

quicksketch’s picture

No, there's no way to do that as far as I know. We could implement Token module support or we could keep using the special Webform tokens for the file path field.

startechglobal’s picture

are there any examples of how I would use the token modules and webform to upload to the designated directory? Or any hacks?

hummingbird’s picture

I'm also interested in this. Any way to use tokens for the upload directory (or any other dynamic value)? Or an example of the 'special Webform tokens' that could be used?

Drupal 6.13, Webform 6.x-2.7.

hummingbird’s picture

Version: 5.x-2.0 » 6.x-2.7

I tried adding one of the placeholders that Webform accepts to the "Upload Directory" field, but it simply creates a folder with the literal value of the placeholder. For example, setting the "Upload Directory" to "photos/%date" simply creates a folder called webform/photos/%date rather than the actual date (webform/photos/20090929 or whatever).

Is there any way to implement the placeholders/tokens for the "Upload Directory" section of a component? Dynamic directory names would be very useful.

Giolf’s picture

up

Scott M. Sanders’s picture

Subscribing.

quicksketch’s picture

Version: 6.x-2.7 » 6.x-3.x-dev
vthirteen’s picture

up

gg4’s picture

+1 for We could implement Token module support or we could keep using the special Webform tokens for the file path field.

jfine’s picture

+1 Tokens in upload field would be handy.

arx-e’s picture

+1 Automatically generated token based subfolders would be great!

sanjaymm’s picture

Hi
How to create directory of every user while uploading file ?
any one know then let me know as soon as possible.

thanks
sanjay mandaliya.

MWildermuth’s picture

+1

hlan’s picture

+1

Polk’s picture

subscribe

derp’s picture

subscribe. +1

dzaretsky’s picture

I created a hack that might help you out. I need to create subdirs for each user to upload files. When creating the directory structure I wanted to automatically append the username to the path. Here's how I did it:

In /components/files.inc, add the following to the function _webform_validate_file(..) :

global $user;
$ext_path = ($user->name ? ('/'.$user->name.'/') : '');
:
:
$upload_dir = file_directory_path() . '/webform/'. $component['extra']['savelocation'] . $ext_path;

Maybe someone can figure out how to use the global symbols in replacing specific tokens in the upload_dir path. Another thing I'm looking for is a way to upload files to an FTP server on a different site instead of the current website itself. Anyone have an idea how to go about doing this?

MXT’s picture

Subscribe and +1 for "We could implement Token module support or we could keep using the special Webform tokens for the file path field."

Marcus 78’s picture

+1

sittard’s picture

+1 - This post is also vaguely related (http://drupal.org/node/364752)

quicksketch’s picture

Title: Changing the File Upload Directory » Support tokens in the File Upload Directory field

Updating title as the topic of this issue has clearly shifted from the first post.

henryblyth’s picture

+1 for comment #3 - We could implement Token module support.

j4’s picture

Any help in integrating tokens with the file directory for webform?

Thanks

Kacey3’s picture

This would be very useful. I'd love to see it in a future version of Webform!

meant’s picture

Agree! Would love to sort files to subfolders based on usernames/dates

raptoplob’s picture

This request has been up for 3 and a half years!

Please implement it as its such a great feature that would help us all out!

quicksketch’s picture

This request has been up for 3 and a half years!

It's been open for that long because no one has written a patch. I don't need this functionality and it's less important than a lot of other feature requests. Considering there are always 100+ feature requests open at any given time, I won't probably give this one my personal priority. If you'd like to move it forward, hire a developer or look into supplying a patch.

Optalgin’s picture

Version: 6.x-3.x-dev » 7.x-4.0-alpha6
Component: Miscellaneous » Code
Assigned: Unassigned » Optalgin
Status: Active » Needs review
FileSize
2.96 KB

Here is a patch I created to solve this on 7.x-4.0-alpha6
Since this is issue is very old I'm updating it to 7.x-4.0-alpha6

There is a minor issue with this solution - a directory is created when webform is
updated (to check the validity of the directory name) however since its about tokens
it might left empty if the name of directory is different when users upload files

ts145nera’s picture

Hello,
I would use %sid as token, is it possible?

toxiclung’s picture

i also need to use $sid as path token. subscribing...

quicksketch’s picture

Status: Needs review » Needs work

i also need to use $sid as path token. subscribing...

It's impossible to use $sid because the submission hasn't been saved to the database yet at the time that the file is uploaded.

Thanks @Optalgin, this patch looks pretty good. Sorry it's been so long, but this looks like it should get this feature into 4.x.

+  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
   $destination_dir = file_stream_wrapper_uri_normalize($scheme . '://' . $directory . '/webform');
-
+  $destination_dir_tokenized = _webform_filter_values($destination_dir, $node, NULL, NULL, TRUE);

The only thing I've seen incorrect is that there's no need to filter the $directory variable here. That's just the path to the overall files directory.

  • DanChadwick committed 6810206 on 7.x-4.x
    Issue #326738 by Optalgin, Dan Chadwick: Support tokens in the File...

  • DanChadwick committed 10607b4 on 8.x-4.x
    Issue #326738 by Optalgin, Dan Chadwick: Support tokens in the File...
DanChadwick’s picture

Version: 7.x-4.0-alpha6 » 7.x-4.x-dev
Issue summary: View changes
Status: Needs work » Fixed
FileSize
3.2 KB

Two years later...

I ported this to 7.x-4.x. I made a few minor changes:

1) I added the token browser help.
2) I convert the tokenized directory to lower case to reduce issues with case-sensitive directories. If this causes issues, I could be convinced to skip this.
3) I removed the condition to replace tokens only when filter is called. That's not what filter means in this context.

Committed to 7.x-4.x and 8.x.

  • DanChadwick committed 74af4b6 on 8.x-4.x
    Issue #326738 by Optalgin, DanChadwick: Support tokens in the File...

  • DanChadwick committed a9e9ff9 on
    Issue #326738 by Optalgin, DanChadwick: Support tokens in the File...
DanChadwick’s picture

Re #36, point 3) -- I take it back. That's exactly what $filter means. My error. This is for Form Builder support.

Committed to 7.x-4.x and 8.x.

Status: Fixed » Closed (fixed)

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

philsward’s picture

Am I correct in saying that since the $sid can't be used, none of the submission tokens can?

My use case was a select list of "departments" with an attachment field. Depending on the department chosen, it would upload the file to that directory.

From what I can tell, the reason it "won't" work, is because webform is trying to accomplish this pre submission. What if it was all handled post submission? In other words, upload the file to a temp directory and once submitted, move the file to the correct location.

It's great that the directories support tokens, but if the tokens can't support submission details, I don't see much use for any of the other tokens...