note 126641 added to features.file-upload.put-method
| From: | willy at kochkonsult dot no | Date: | Thu, 25 Nov 2021 13:35:09 +0000 |
| Subject: | note 126641 added to features.file-upload.put-method | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217298@lists.php.net to get a copy of this message | ||
All the example code I found for using PUT with PHP always used a default hard-coded file extension
for the incoming stream.
The filename from the incoming file PUT request can't be found anywhere from the incoming
request (at least I couldn't find it) but mimetype can be found in the $_SERVER global
variable.
I used this code to get the correct file extension:
$mimeType = $_SERVER['HTTP_CONTENT_TYPE'];
if ($mimeType!='application/pdf')
{
header('HTTP/1.1 405 Only PDF files allowed');
echo("Only PDF files are allowed for upload - this file is ".$mimeType);
die();
}
else $fileExtension = 'pdf';
If you have an Apache Tika server available, that would be the best option to analyze the file
content to get the mimetype, but that might not be in scope for everyone :-)
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 193.15.240.60)
----
Manual Page -- https://php.net/manual/en/features.file-upload.put-method.php
Edit -- https://main.php.net/note/edit/126641
Del: integrated -- https://main.php.net/note/delete/126641/integrated
Del: useless -- https://main.php.net/note/delete/126641/useless
Del: bad code -- https://main.php.net/note/delete/126641/bad+code
Del: spam -- https://main.php.net/note/delete/126641/spam
Del: non-english -- https://main.php.net/note/delete/126641/non-english
Del: in docs -- https://main.php.net/note/delete/126641/in+docs
Del: other reasons-- https://main.php.net/note/delete/126641
Reject -- https://main.php.net/note/reject/126641
Search -- https://main.php.net/manage/user-notes.php