Skip to content
Snippets Groups Projects
getFile.php 996 B
Newer Older
nicrausaz's avatar
nicrausaz committed
<?php
  require('configs/db.php');
  include('./helpers.php');
  require_once("tequila/tequila.php");
  $oClient = new TequilaClient();
  $oClient->SetApplicationName('Formulaire apprentissage');
  $oClient->SetWantedAttributes(array('uniqueid','firstname','name'));
  $oClient->SetWishedAttributes(array('user'));
  $oClient->SetAllowsFilter('categorie=epfl-guests');
  $oClient->Authenticate();
  $user = $oClient->getValue('user');
  $firstname = $oClient->getValue('firstname');
  $name = $oClient->getValue('name');
  $guest_sciper = $oClient->getValue('uniqueid');
  $sKey = $oClient->GetKey();

  if (isset($_GET['id'])) {
    // check if sciper is linked to file
    $file = validFileAccess($pdo, $_GET['id'], $guest_sciper)[0];
    if ($file) {
      // get file
      echo file_get_contents($file['file_path']);
      // send file
      header('Content-Disposition: attachment; filename='.$file['file_name']);
    } else {
      echo "Fichier inexistant ou accès refusé";
    }
  }
?>