70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
if (!defined('_ECRIRE_INC_VERSION')) return;
|
|
|
|
function action_charger_document_dist($arg=null){
|
|
|
|
$securiser_action = charger_fonction('securiser_action', 'inc');
|
|
$arg = $securiser_action();
|
|
|
|
include_spip('inc/autoriser');
|
|
if (! autoriser("charger","document")) {
|
|
return false;
|
|
}
|
|
|
|
$id_document = $arg;
|
|
charger_ce_document($id_document);
|
|
}
|
|
|
|
|
|
function charger_ce_document($id_document){
|
|
|
|
$from = [
|
|
'spip_documents AS D',
|
|
'spip_types_documents AS T'
|
|
];
|
|
$where = [
|
|
'D.id_document='.intval($id_document),
|
|
'D.extension=T.extension'
|
|
];
|
|
$d = sql_fetsel('D.extension,D.fichier,D.protected,T.mime_type', $from, $where);
|
|
|
|
// si pas d'enregistrement en bdd
|
|
if (empty($d)) {
|
|
return false;
|
|
}
|
|
$chemin_fichier = _DIR_IMG . 'PROTECTED/'. $d['fichier'];
|
|
|
|
// Test si le fichier exciste
|
|
if (!file_exists($chemin_fichier)) {
|
|
return false;
|
|
}
|
|
|
|
// Test si le fichier est accessible en lecture
|
|
if (!is_readable($chemin_fichier)) {
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
// recup de acces restreint :
|
|
// action/api_docrestreint.php
|
|
// function accesrestreint_afficher_document(Accesrestreint_document $Document)
|
|
*/
|
|
header('Content-Type: ' . $d['mime_type']);
|
|
$f = basename($chemin_fichier);
|
|
// ce content-type est necessaire pour eviter des corruptions de zip dans ie6
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header("Content-Disposition: attachment; filename=\"$f\";");
|
|
header('Content-Transfer-Encoding: binary');
|
|
|
|
// fix for IE catching or PHP bug issue
|
|
header('Pragma: public');
|
|
header('Expires: 0'); // set expiration time
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
|
|
if ($size = filesize($chemin_fichier)) {
|
|
header('Content-Length: '. $size);
|
|
}
|
|
|
|
readfile($chemin_fichier);
|
|
}
|