Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Registered file upload, anonymous file download

Started by Sven 8 years ago · 1 replies · 1074 views
8 years ago

Hi!

Newbie here, but I managed to install everything on my raspberry pi to get Grav up and running.

What I'd like to do is learn how to build a website similar in functionality to http://www.mircscripts.org and create a place for users to register, upload their code (.mrc or collection of files in .zip format) so that those files are displayed publicly.

So far I managed to make a file upload section in Grav:

YAML
title: Upload
process:
    markdown: true
    twig: true
access:
    site:
        login: true
form:
    name: upload
    fields:
        -
            name: description
            label: Description
            type: text
            validate:
                required: true
        -
            type: select
            size: medium
            label: Type
            options:
                script: 'Script (.zip)'
                addon: 'Addon (.mrc or .ini)'
                dll: 'DLL (.zip)'
                mts: 'Theme (.zip)'
        -
            name: myfile
            label: 'My File'
            type: file
            destination: user/data/upload
            multiple: false
            random_name: true
            avoid_overwriting: true
            accept:
                - .zip
                - .mrc
                - .ini
    buttons:
        -
            type: submit
            value: Submit
    process:
        -
            email:
                from: '{{ config.plugins.email.from }}'
                to: ['{{ config.plugins.email.from }}', '{{ grav.user.email }}']
                subject: '[Feedback] {{ form.value.name|e }}'
                body: '{% include ''forms/data.html.twig'' %}'
        -
            save:
                fileprefix: feedback-
                dateformat: dmY-His-u
                extension: txt
                body: '{% include ''forms/data.txt.twig'' %}'
        -
            message: 'Thank you for your feedback!'
        -
            display: thankyou

For now I'm looking for a way for Grav to display in /home all uploaded files with a bit of extra data. For example:

Upload date Description Type Size Username Download
13-01-2018 Peace and Protection 4.22.7 .zip 1151497 admin click here to download

I should be able to retrieve all this data from the feedback-.txt files. How do I read the feedback-.txt files and build a simple table so that anonymous users can download the files from the /home page?

kind regards!

8 years ago

I'm now looking at the following:
https://learn.getgrav.org/cookbook/plugin-recipes#how-do-i-read-from-and-write-data-to-the-file-system

Also, I've installed the comments plugin and started looking at how it works. I suppose I will try to answer my own question in this thread!

edit:
It seems flex-directory plugin is what I desire. I shall follow the instructions as found here: https://github.com/trilbymedia/grav-plugin-flex-directory

Then, I have to figure out what the mechanism is for front-end to CRUD the data in the entries.json file...

last edited 01/16/18 by Sven

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 54 12 hours ago
Support · by Anna, 3 days ago
2 60 15 hours ago
Support · by Justin Young, 16 hours ago
1 30 15 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 57 5 days ago