Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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/?
Comment | File | Size | Author |
---|---|---|---|
#39 | webform-file_directory_tokens-326738-37.patch | 1.59 KB | DanChadwick |
#36 | webform-file_directory_tokens-326738-34.patch | 3.2 KB | DanChadwick |
#30 | webform-7.x-4.x-326738-tokenized-upload-directory.patch | 2.96 KB | Optalgin |
Comments
Comment #1
quicksketchNot currently. Webform keeps all files uploaded inside the "[files]/webform" directory.
Comment #2
startechglobal CreditAttribution: startechglobal commentedis there anyway to upload to a dynamically named directory such as /files/webform/xxusernamexx/ ?
Comment #3
quicksketchNo, 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.
Comment #4
startechglobal CreditAttribution: startechglobal commentedare there any examples of how I would use the token modules and webform to upload to the designated directory? Or any hacks?
Comment #5
hummingbird CreditAttribution: hummingbird commentedI'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.
Comment #6
hummingbird CreditAttribution: hummingbird commentedI 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.
Comment #7
Giolf CreditAttribution: Giolf commentedup
Comment #8
Scott M. Sanders CreditAttribution: Scott M. Sanders commentedSubscribing.
Comment #9
quicksketchComment #10
vthirteen CreditAttribution: vthirteen commentedup
Comment #11
gg4 CreditAttribution: gg4 commented+1 for We could implement Token module support or we could keep using the special Webform tokens for the file path field.
Comment #12
jfine CreditAttribution: jfine commented+1 Tokens in upload field would be handy.
Comment #13
arx-e CreditAttribution: arx-e commented+1 Automatically generated token based subfolders would be great!
Comment #14
sanjaymm CreditAttribution: sanjaymm commentedHi
How to create directory of every user while uploading file ?
any one know then let me know as soon as possible.
thanks
sanjay mandaliya.
Comment #15
MWildermuth CreditAttribution: MWildermuth commented+1
Comment #16
hlan CreditAttribution: hlan commented+1
Comment #17
Polk CreditAttribution: Polk commentedsubscribe
Comment #18
derp CreditAttribution: derp commentedsubscribe. +1
Comment #19
dzaretsky CreditAttribution: dzaretsky commentedI 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?
Comment #20
MXTSubscribe and +1 for "We could implement Token module support or we could keep using the special Webform tokens for the file path field."
Comment #21
Marcus 78 CreditAttribution: Marcus 78 commented+1
Comment #22
sittard CreditAttribution: sittard commented+1 - This post is also vaguely related (http://drupal.org/node/364752)
Comment #23
quicksketchUpdating title as the topic of this issue has clearly shifted from the first post.
Comment #24
henryblyth CreditAttribution: henryblyth commented+1 for comment #3 - We could implement Token module support.
Comment #25
j4 CreditAttribution: j4 commentedAny help in integrating tokens with the file directory for webform?
Thanks
Comment #26
Kacey3 CreditAttribution: Kacey3 commentedThis would be very useful. I'd love to see it in a future version of Webform!
Comment #27
meant CreditAttribution: meant commentedAgree! Would love to sort files to subfolders based on usernames/dates
Comment #28
raptoplob CreditAttribution: raptoplob commentedThis 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!
Comment #29
quicksketchIt'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.
Comment #30
Optalgin CreditAttribution: Optalgin commentedHere 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
Comment #31
ts145nera CreditAttribution: ts145nera commentedHello,
I would use %sid as token, is it possible?
Comment #32
toxiclung CreditAttribution: toxiclung commentedi also need to use $sid as path token. subscribing...
Comment #33
quicksketchIt'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.
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.
Comment #36
DanChadwick CreditAttribution: DanChadwick commentedTwo 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.
Comment #39
DanChadwick CreditAttribution: DanChadwick commentedRe #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.
Comment #41
philsward CreditAttribution: philsward commentedAm 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...