1

In Drupal 7, I have the file system configured as

enter image description here

In the code for the Webforms' file component located at sites/all/modules/webform/components/file.inc, it appears that one could easily change it so that Webform file uploads are moved to the private file system by changing 'scheme' => 'public' to 'scheme' => 'private'. But I also know the pitfalls of hacking (changing) anything that could easily be overwritten with drush upc.

 /** * Implements _webform_defaults_component(). */ function _webform_defaults_file() { return array( 'name' => '', 'form_key' => NULL, 'required' => 0, 'pid' => 0, 'weight' => 0, 'extra' => array( 'filtering' => array( 'types' => array('gif', 'jpg', 'png'), 'addextensions' => '', 'size' => '2 MB', ), 'scheme' => 'public', 'directory' => '', 'progress_indicator' => 'throbber', 'title_display' => 0, 'description' => '', 'attributes' => array(), 'private' => FALSE, 'analysis' => FALSE, ), ); } 

Given that all file uploads are stored referenced in the file_managed table

mysql> describe file_managed; +-----------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------------+------+-----+---------+----------------+ | fid | int(10) unsigned | NO | PRI | NULL | auto_increment | | uid | int(10) unsigned | NO | MUL | 0 | | | filename | varchar(255) | NO | | | | | uri | varchar(255) | NO | UNI | | | | filemime | varchar(255) | NO | | | | | filesize | bigint(20) unsigned | NO | | 0 | | | status | tinyint(4) | NO | MUL | 0 | | | timestamp | int(10) unsigned | NO | MUL | 0 | | +-----------+---------------------+------+-----+---------+----------------+ 

Is it feasible to do a post operation to a file upload that manually moves a file from public:// to private:// and updates the database entry? Would hook_file_presave or hook_file_insert be good tools to accomplish this?

Update

Based on the suggestion of using hook_webform_component_info_alter(), I implemented the following

/** * Implements hook_webform_component_info_alter(). */ function MYMOD_webform_component_info_alter(&$components) { $components['file']['extra']['scheme'] = 'private'; dsm($components['file']); } /** * Implements hook_file_insert(). */ function MYMOD_file_insert($file) { dsm($file); } 

After the output of the DSM() shows the component array seems to be altered but the DSM from hook_file_insert() still shows that the file was deposited into the public area:

enter image description here

4
  • 1
    I'm just guessing, I haven't looked into this situation all that much but I see in the code from Webform under the extra array there is a 'private' => FALSE, can you change that to TRUE in your hook along with your other modification. That may change the 'public://' to 'private://' but still just a shot in the dark. Commented Jan 23, 2015 at 16:19
  • The "Private" I believe means 'show only to administrators' in this scenario. But I just tried with $components['file']['extra']['private'] = TRUE; and no luck. The file upload still gets throw into sites/default/files/webform/upload. Commented Jan 23, 2015 at 16:26
  • 1
    Worth a shot, did look a little more into this. There is a setting for this in webform I believe. There was an issue posted in the webform issues but it has been resolved. drupal.org/node/1201084 I will have to load up webform to test and give further instructions. Commented Jan 23, 2015 at 16:36
  • @burnsjeremy Yes!! #10 solved a few days ago. I reinstalled webform to my vagrant instance and refreshed (drush cc all && drush cron). It now appears in the Field's settings!! Mind moving your comment down into the answer? drupal.org/node/1201084#comment-9490409 Commented Jan 23, 2015 at 16:40

2 Answers 2

2

Did a little digging into Webform. There is a setting for this in webform I believe. There was an issue posted in the webform issues but it has been resolved. Saving file submission to private directory

OP already solved but for future onlookers: There are instructions I believe on how to accomplish this in the comments of the issue referenced above, also make sure Webform is up-to-date.

1

Webform itself has an API. You could change the scheme from public to private without hacking the module by implementing hook_webform_component_info_alter().

In a custom module this would look like:

function MYMODULE_webform_component_info_alter(&$components) { $components['file']['extra']['scheme'] = 'private'; } 
3
  • I updated the question with the results of using this hook. No go unfortunately. Still get an upvote for introducing me to webforms' hooks. Commented Jan 23, 2015 at 16:12
  • Interesting. if I have time I'll try to look at it more, but I'm busy atm. Commented Jan 23, 2015 at 16:16
  • Oh please, no worries. Thank you for the initial suggestion. Commented Jan 23, 2015 at 16:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.