Use LSurl route to handle tmp file access

This commit is contained in:
Benjamin Renard 2020-05-04 17:55:46 +02:00
parent add68ec132
commit 958c5b16a8
3 changed files with 37 additions and 0 deletions

View file

@ -1,5 +1,8 @@
RewriteEngine On
# Always rewrite tmp file access
RewriteRule ^(tmp/.*)$ index.php?REQUESTED_URL=$1 [L,QSA]
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link

View file

@ -2369,6 +2369,24 @@ class LSsession {
return False;
}
/**
* Retourne le chemin du fichier temporaire à partir du nom du fichier (s'il existe)
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $hash La valeur du fichier
*
* @retval mixed
**/
public static function getTmpFileByFilename($filename) {
foreach(self :: $tmp_file as $filePath => $contentHash) {
if (basename($filePath) == $filename) {
return $filePath;
}
}
return False;
}
/**
* Supprime les fichiers temporaires
*

View file

@ -249,6 +249,22 @@ function handle_image($request) {
}
LSurl :: add_handler('#^image/(?P<image>[^/]+)$#', 'handle_image', false);
/*
* Handle tmp file request
*
* @param[in] $request LSurlRequest The request
*
* @retval void
**/
function handle_tmp_file($request) {
$path = LSsession :: getTmpFileByFilename($request -> filename);
if ($path && is_file($path)) {
dumpFile($path);
}
LSurl :: error_404($request);
}
LSurl :: add_handler('#^tmp/(?P<filename>[^/]+)$#', 'handle_tmp_file');
/*
************************************************************
* LSobject views