mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 06:30:07 +01:00
fix: download filenames can sometimes be pretty weird.
This commit is contained in:
parent
c19139ed6e
commit
ec562cef57
2 changed files with 14 additions and 1 deletions
|
@ -298,3 +298,15 @@ function paginate(int $current_page, int $per_page, int $total_records) : string
|
|||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function pp_filename_escape(string $filename, string $extension) : string {
|
||||
/* Remove NTFS invalid characters */
|
||||
$filename = preg_replace('#[<>:"/|?*]#', '-', $filename);
|
||||
|
||||
/* Windows MAX_PATH limit */
|
||||
if (strlen($filename . $extension) > 255) {
|
||||
$filename = substr($filename, 0, 255 - strlen($extension));
|
||||
}
|
||||
|
||||
return $filename . $extension;
|
||||
}
|
|
@ -155,8 +155,9 @@ $op_content = trim(htmlspecialchars_decode($p_content));
|
|||
|
||||
// Download the paste
|
||||
if (isset($_GET['download'])) {
|
||||
$filename = pp_filename_escape($paste->title . '_' . $paste->user->username, '.txt');
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-Disposition: attachment; filename="' . $paste->id . '_' . pp_html_escape($paste->title) . '_' . pp_html_escape($paste->user->username) . '.txt"');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
echo $op_content;
|
||||
exit();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue