Last active
March 18, 2021 21:12
Revisions
-
kitsaels revised this gist
Jun 4, 2019 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ <?php function parseProperties($message) { $properties = explode(';', $message); $result = array(); foreach ($properties as $prop) { $property = trim($prop); $pos = strpos($property, '='); if ($pos > 0) { $key = trim(substr($property, 0, $pos)); $val = trim(substr($property, $pos+1)); if (strlen($val) > 0 && $val{0} == '"') { $val = substr($val, 1, -1); } $result[$key] = $val; } } return $result; } -
kitsaels revised this gist
Jun 3, 2019 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ function getFilename($header) { return $matches[1]; } if (preg_match('/Content-Disposition:.*?filename=([^; ]+)/', $header, $matches)) { return rawurldecode($matches[1]); } throw new Exception(__FUNCTION__ .": Filename not found"); } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ function getFilename($header) { return $matches[1]; } if (preg_match('/filename=([^; ]+)/', $header, $matches)) { return rawurldecode($matches[1]); } throw new Exception(__FUNCTION__ .": Filename not found"); } -
kitsaels revised this gist
Jun 3, 2019 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ <?php function getFilename($header) { if (preg_match('/filename="(.+?)"/', $header, $matches)) { return $matches[1]; } if (preg_match('/filename=([^; ]+)/', $header, $matches)) { return $matches[1]; } throw new Exception(__FUNCTION__ .": Filename not found"); } header("Content-Type: text/plain;charset=UTF-8"); $s1 = 'attachment; filename="FILE NAME HERE"'; echo getFilename($s1) . PHP_EOL; $s2 = 'attachment; filename=file.ext'; echo getFilename($s2) . PHP_EOL; $s3 = $_SERVER['HTTP_CONTENT_DISPOSITION'] ?? ""; echo getFilename($s3) . PHP_EOL; -
kitsaels created this gist
Jun 3, 2019 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ <?php function getFilename($header) { if (preg_match('/Content-Disposition:.*?filename="(.+?)"/', $header, $matches)) { return $matches[1]; } if (preg_match('/Content-Disposition:.*?filename=([^; ]+)/', $header, $matches)) { return $matches[1]; } throw new Exception(__FUNCTION__ .": Filename not found"); } $s1 = 'Content-Disposition: attachment; filename="FILE NAME HERE"'; echo getFilename($s1) . PHP_EOL; $s2 = 'Content-Disposition: attachment; filename=file.ext'; echo getFilename($s2) . PHP_EOL; $s3 = 'Content-Disposition: attachment; name=file.ext'; echo getFilename($s3) . PHP_EOL;