PHP Nette - how to download files above the www directory (from root)

PHP Nette - how to download files above the www directory (from root)

Hello,

I would need to use a function on my website, which is written in PHP Nette, that would allow downloading files outside the usual path of web / www / uploads from web / uploads, ie. from a directory at the same level as app, vendor, www ... How could this be solved? The goal is that the file path is not visible to the visitor and cannot be downloaded by "tipping" the file path. Thanks

REPLY


Hello

yes, I handle downloading above the www directory in Nette as follows:


public function getFile($up_id)
{
$document_root = $_SERVER['DOCUMENT_ROOT'];

//odebere www na konci v ceste $document_root
$path = substr($document_root, 0, -3);
$file = $this->getUpload($up_id);
$file = $path . $file->up_path;

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
}
return $file;
}

Související obsah

programovani

nette

php

Komentáře

Vaše reakce na PHP Nette - jak stahovat soubory nad adresářem www (z rootu)

Reference

Podívejte se na naše reference

Prohlédnout

Aplikace

Podívejte se na naše aplikace

Prohlédnout

Co umíme?

Podívejte se co umíme

Prohlédnout

Co umíme?

Vytváříme sofistikované aplikace pro náročné

Od webových aplikací přes android až po převodové můstky či složité informační systémy.

Podívejte se k nám

Máte ještě čas? Podívejte se na další rubriky

Tento web používá soubory cookie. Dalším procházením tohoto webu vyjadřujete souhlas s jejich používáním.. Více informací zde.