Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a curl implementation from the filefield_sources module in Drupal. It can probably work anywhere:</p> <pre><code>&lt;?php // Inspect the remote image // Check the headers to make sure it exists and is within the allowed size. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADERFUNCTION, '_filefield_source_remote_parse_header'); // Causes a warning if PHP safe mode is on. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); /** * Parse cURL header and record the filename specified in Content-Disposition. */ function _filefield_source_remote_parse_header(&amp;$ch, $header) { if (preg_match('/Content-Disposition:.*?filename="(.+?)"/', $header, $matches)) { // Content-Disposition: attachment; filename="FILE NAME HERE" _filefield_source_remote_filename($matches[1]); } elseif (preg_match('/Content-Disposition:.*?filename=([^; ]+)/', $header, $matches)) { // Content-Disposition: attachment; filename=file.ext _filefield_source_remote_filename($matches[1]); } // This is required by cURL. return strlen($header); } /** * Get/set the remote file name in a static variable. */ function _filefield_source_remote_filename($curl_filename = NULL) { static $filename = NULL; if (isset($curl_filename)) { $filename = $curl_filename; } return $filename; } ?&gt; </code></pre> <p>To get the mime:</p> <pre><code>&lt;?php echo $info['content_type']; ?&gt; </code></pre> <p>Code is here: <a href="http://drupal.org/project/filefield_sources" rel="nofollow">http://drupal.org/project/filefield_sources</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload