Drupal 8 to publish files - drupal

I'm trying to create a simple CMS to ingest contents and publish files. I'm using Drupal 8 with Feeds module to read xml files from a directory and it works fine.
I can't figure it out how I can take the information saved in my custom content and publish them to a file in another directory.
Anyone can help?
Thx
Luca

Could you create a view to render the desired output for the content you're after and then use the Views data export module to export that view into a file?
I note the following:
This module also exposes a drush command that can execute the view and
save its results to a file.
drush views-data-export [view-name] [display-id] [output-file]
If you can do it with Drush you can do it with PHP.
So potentially you could write hooks to manage the export of files based on the activity of the feed. E.g. The hook_ENTITY_TYPE_insert would allow you to perform logic when a node of a particular content type is created.

Related

How would I go about creating a simple file builder?

Forgive me if this doesn't make sense but I'll do my best to explain.
I am looking into creating a piece of software/web app which will generate a package file for website themes including only the options the user would need for their project.
The best example I can think of is the underscores WordPress theme generator. But I would also like to be able to include other files. Like for example a check box that simply says "include x.js library" where if the box is checked it will include that js file or files in the folder. As well as generate the theme name, author name, theme description version number etc.
In other words I need something like underscores, that also has the option to include extra files for the development team to quickly get bespoke WordPress themes up and running whilst also including all the optional assets that we use at the firm.
You can hold the basic logic, opening, reading, editing, closing of files in a php script that's triggered when the user submits a form.
One route to manipulate files on the server with php is to use fopen.
First enable fopen in the directory in which your files you want available for download are stored. Do this by including the following in a .htaccess file in this directory:
php_value allow_url_fopen On
In whatever script you would like triggered on form submit, you can change say the author name with something like the following (you'll obviously want to target where you're writing to, I imagine with FSeek):
$downloadable_theme_index = 'index.php';
$handle = fopen($downloadable_theme_index, 'w') or die('Cannot open file: '.$downloadable_theme_index);
$new_author_name = 'Abe Lincoln';
fwrite($handle, $new_author_name);
The logic for what files are available to download could basically be form logic that provides links to download based on user input.
Additionally, there are download manager plugins available in wordpress.

Drupal webform file upload not saving to database

I'm writing a custom Drupal module for a mobile service. That module acts like a web form, but I'm having a problem when uploading a file. All values are inserted into the database successfully except for the file.
I think the function "_webform_client_form_submit_process" is not calling "_webform_submit_file". You can try following solution
1. Try using updating your webform module with the latest release.
2. Try removing your file upload field from fieldset, if its in any.
3. Check the temp and destination directory permission.
I've almost went over the code of the webform module and I solved it now, you have to use file_save and get the $file->fid and pass it to the data object of the submissions object, then call webform_submission_insert and get the $sid and pass it to file_usage_add, this got my module working

Wordpress File Upload Hook

I am trying to hook into the Wordpress file uploader and would like some suggestions. I would like to be able to grab the path of the source file (not WP path; i.e. K:\docs\file.pdf) so I can download another file of the same name (different extension) & path automatically (i.e. K:\docs\file.txt).
Wordpress provides hooks for after the file is uploaded but all path information at that point is internal to wordpress.
Thanks in advance!!
the path information can be obtained from normal php functions like pathinfo() and realpath() for example .
Bit too late to the party but I think what you are asking for is to find the source of the document in the clients system and based on that you want similar files there to be picked up by the browser and then sent to the user.
I think it will be a fairly complex thing to do, firstly you have to get the source of the document being added to the browser (I am not sure it can be done, but if it can be done then it will be via javascript) and then upload all the files one by one to the server hosting wordpress and you can do this by creating a custom page which will add the files uploaded to it as a wordpress attachment and then using something like jquery file uploader to upload files to that location.
But honestly, I think it would be a very complex thing, unless the client and the server are on the same machine.

Drupal6: I need to customize file upload links in node edit form

I am customizing the node/add and node/edit forms of a content type with a form_alter. In my content type, there is a file field that permits to upload files to the content.
What I would like to do is to customize the file box by changing the link to the file that is composed at runtime with Ajax. How can I do it without modifying Drupal core?
Your Private Files directory should not be in the docroot. Hiding it with a .htaccess rule will not work, as you point out in a comment.
Say you have Drupal in /var/www/sites/example.com/, then you should not store your private files under that directory; /var/www/sites/example.com/sites/default/private/files/ is just plain wrong.
You should, instead store the files where apache will not serve them, but can read them. E.g. in /var/www/files/example.com/. Then change the setting in Drupal to use that absolute path.
If you are running a large(r) site, you will probably want to store your files on a dedicated mount (drive, NFS etc.), say /media/nfs-example-com/.
Try Filefield Paths:
The FileField Paths module extends the default functionality of Drupals core Upload module, the FileField module and many other File Upload modules by adding the ability to use node tokens in destination paths and filenames.
http://drupal.org/project/filefield_paths

How to store Blobs in Drupal?

I want to store PDF and Image files in Drupal. By default Drupal seems to store binary/uploaded files into the filesystem. I want to to be able to store files so that - I can have workflows, metadata, IP information and URL aliases?
Update, am still stuck at how to create URL aliases for files on the file system. Drupal only seems to allow creating URL aliases to node content.
The simplest solution for Drupal is to use the Upload module, which is in core. The upload module allows you attach files to nodes. As you note, they are stored in the filesystem.
If you want to get more complex, you can build your own content types through the web interface by using the CCK family of modules (such as the filefield module or the imagefield module). Your files are still stored on the filesystem.
You could use CCK to create the metadata field you want.
You could use the workflow or rules modules to implement workflow.
IP information is recorded automatically by Drupal's logging module (either the database logging module, which logs to the database, or the syslog module, which logs to syslog).
URL aliases for nodes are available in core Drupal by enabling the path module (or download the pathauto module for automatic creation of aliases).
I tried Drupal's Upload module, FileField as well as uploading files using FCKEditor - I prefer the last one - it is closer to my specific scenario.
Creating an alias to the file will likely require some custom code.
It's not possible to simply create an alias using the Administer > Site building > URL aliases screen. I tried inserting a record with
insert into url_alias (src, dst) values ('sites/default/files/ChipotleArt.JPG', 'here-is-the-file.jpg');
That still didn't work. So, you will really likely need to write some custom code.

Resources