note 127655 added to function.file-get-contents

From: Date: Tue, 20 Sep 2022 12:54:04 +0000
Subject: note 127655 added to function.file-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-219601@lists.php.net to get a copy of this message
There's barely a mention on this page but the $http_response_header will be populated with the HTTP headers if your file was a link. For example if you're expecting an image you can do this: <?php $data = file_get_contents('https://example.net/some-link'); $mimetype = null; foreach ($http_response_header as $v) { if (preg_match('/^content\-type:\s*(image\/[^;\s\n\r]+)/i', $v, $m)) { $mimetype = $m[1]; } } if (!$mimetype) { // not an image } ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.173 (proxied: 82.79.50.10) ---- Manual Page -- https://php.net/manual/en/function.file-get-contents.php Edit -- https://main.php.net/note/edit/127655 Del: integrated -- https://main.php.net/note/delete/127655/integrated Del: useless -- https://main.php.net/note/delete/127655/useless Del: bad code -- https://main.php.net/note/delete/127655/bad+code Del: spam -- https://main.php.net/note/delete/127655/spam Del: non-english -- https://main.php.net/note/delete/127655/non-english Del: in docs -- https://main.php.net/note/delete/127655/in+docs Del: other reasons-- https://main.php.net/note/delete/127655 Reject -- https://main.php.net/note/reject/127655 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219601) next »