This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

d.negativa
d.negativa

How to download a file that was previously uploaded? I can upload a file in the backend side, but how to download this file from the frontend side?

Model Item.php


public $attachMany = [
        'my_files'             => ['System\Models\File', 'order' => 'sort_order'],
        'featured_images'   => ['System\Models\File', 'order' => 'sort_order'],
    ];

fields.yaml


    my_files:
      tab: File
      label: File
      type: fileupload
      options: 
        mode: file

Last updated

daftspunky
daftspunky

Using PHP:

// Get the file object (many ways to do this, it is a normal relation)
$file = $item->featured_images()->first();

// If the file is public, this will return the direct location
echo $file->getPath(); 

// If the file is private, you will need to return the contents via a script
// This will include the necessary header to download the file
echo $file->output();
daftspunky
daftspunky

In Twig:

<a class="btn btn-danger btn-lg" href="{{ item.myfiles.first.path }}">
<span class="glyphicon glyphicon-download"></span>
         Follow
</a>
d.negativa
micwanyoike5462
micwanyoike5462

I got the same error too. Any resolution

jakobf
jakobf

This is because the file extension blend is not whitelisted in the htacces in the root of october. Currently whitelisted are:

##
## White listed folders and files
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} !\.js
RewriteCond %{REQUEST_URI} !\.map
RewriteCond %{REQUEST_URI} !\.ico
RewriteCond %{REQUEST_URI} !\.jpg
RewriteCond %{REQUEST_URI} !\.jpeg
RewriteCond %{REQUEST_URI} !\.gif
RewriteCond %{REQUEST_URI} !\.css
RewriteCond %{REQUEST_URI} !\.less
RewriteCond %{REQUEST_URI} !\.scss
RewriteCond %{REQUEST_URI} !\.pdf
RewriteCond %{REQUEST_URI} !\.png
RewriteCond %{REQUEST_URI} !\.swf
RewriteCond %{REQUEST_URI} !\.txt
RewriteCond %{REQUEST_URI} !\.xml
RewriteCond %{REQUEST_URI} !\.xls
RewriteCond %{REQUEST_URI} !\.eot
RewriteCond %{REQUEST_URI} !\.woff
RewriteCond %{REQUEST_URI} !\.woff2
RewriteCond %{REQUEST_URI} !\.ttf
RewriteCond %{REQUEST_URI} !\.svg
RewriteCond %{REQUEST_URI} !\.wmv
RewriteCond %{REQUEST_URI} !\.mp3
RewriteCond %{REQUEST_URI} !\.wav
RewriteCond %{REQUEST_URI} !\.avi
RewriteCond %{REQUEST_URI} !\.mov
RewriteCond %{REQUEST_URI} !\.mp4
RewriteCond %{REQUEST_URI} !\.webm
RewriteCond %{REQUEST_URI} !\.ogg
RewriteCond %{REQUEST_URI} !docs/.*
RewriteCond %{REQUEST_URI} !themes/.*
RewriteRule ^ index.php [L,NC]

You might change the .htaccess by adding RewriteCond %{REQUEST_URI} !\.blend before the RewriteRule but I'm not sure if it's overwritten when the core gets updated...

Cpt.Meatball
Cpt.Meatball

As far as I'm aware October doesn't overwrite your .Htacces. At least not with nginx as it's located in the server block.

manrox.drag17392
manrox.drag17392

daftspunk said:

Using PHP:

// Get the file object (many ways to do this, it is a normal relation)
$file = $item->featured_images()->first();

// If the file is public, this will return the direct location
echo $file->getPath(); 

// If the file is private, you will need to return the contents via a script
// This will include the necessary header to download the file
echo $file->output();

output method Does not exists when used in controller

manrox.drag17392
manrox.drag17392

manrox.drag17392 said:

daftspunk said:

Using PHP:

// Get the file object (many ways to do this, it is a normal relation)
$file = $item->featured_images()->first();

// If the file is public, this will return the direct location
echo $file->getPath(); 

// If the file is private, you will need to return the contents via a script
// This will include the necessary header to download the file
echo $file->output();

output method Does not exists when used in controller

also getPath() method also shows method does not exists in controller

K.Singh
K.Singh

daftspunk said:

In Twig:

<a class="btn btn-danger btn-lg" href="{{ item.myfiles.first.path }}">
<span class="glyphicon glyphicon-download"></span>
        Follow
</a>

what is item here

1-10 of 10

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.