download_file invalid file 404 instead of 200

62 Views Asked by At

Is there a way to throw a 404 instead of a 200 when we try to download an invalide file "/download_file/view/myFile.test" in concrete 5. I'm using version 8.2.1

Thanks for your help

1

There are 1 best solutions below

0
On

The solution was to override the DownloadFile controller and the view method:

namespace Application\Controller\SinglePage;

use PageController;
use Core;
use Page;
use Permissions;
use Concrete\Core\Entity\File\File as FileEntity;
use Concrete\Core\File\File;
use Concrete\Controller\SinglePage\DownloadFile as CoreDownloadFile;

class DownloadFile extends CoreDownloadFile
{
    /**
     * @param int $fID
     * @param null $rcID
    * @return bool
     */
    public function view($fID = 0, $rcID = null)
    {
      //your code
      //redirect to 404 whenever you want: 
      $this->replace('/page_not_found');

      //...
    }
}