Ajout de l'action pour telecharger le doc
This commit is contained in:
parent
ad74d1f1e9
commit
c1e8e438e6
3 changed files with 76 additions and 1 deletions
70
action/charger_document.php
Normal file
70
action/charger_document.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
if (!defined('_ECRIRE_INC_VERSION')) return;
|
||||
|
||||
function action_charger_document_dist(){
|
||||
|
||||
$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);
|
||||
}
|
|
@ -19,3 +19,8 @@ if (!defined('_ECRIRE_INC_VERSION')) {
|
|||
* @pipeline autoriser */
|
||||
function bigform_autoriser() {
|
||||
}
|
||||
|
||||
|
||||
function autoriser_document_charger_dist($faire, $type, $id, $qui, $opt) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ function urls_propres2($i, &$entite, $args = '', $ancre = '') {
|
|||
if (sql_countsel('spip_documents',['id_document='.$i, 'protected="oui"'])) {
|
||||
//return generer_url_action('charger_document','id_document='.$i);
|
||||
include_spip('inc/securiser_action');
|
||||
return securiser_action_auteur('charger_document','id_document='.$i);
|
||||
return securiser_action_auteur('charger_document',$i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue