PHP: Funzione per download

Vi piacerebbe inserire all’interno del vostro sito un sistema che simula lo scaricamento di un file tipo allegato di posta elettronica o cose simili?Ecco il codice, per utilizzarla basta richiamare il file contenente la pozione della web root indicando i parametri.

 
php
function allegato($percorso,$nome_file)
{
@header('Pragma: private');
@header('Cache-control: private, must-revalidate');
@header("Content-Type: application/octet-stream");
@header("Content-Length: " .(string)(@filesize($percorso)) );
@header('Content-Disposition: attachment; filename="'.($nome_file).'"');
@readfile($percorso);
@exit;
}
?

Articoli simili

Lascia un commento

Your email is never published nor shared. Required fields are marked *

*
*

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a