Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I download an image over HTTP with unicode letters in URL?
    text
    copied!<p>How can I download the following URL (image) using PHP: <code>http://www.delo.si/assets/media/picture/20121228/POLITIČNI05 tomi lombar.jpg?rev=2</code>?</p> <p>The problem is that PHP somehow doesn't support unicode letters in the URL (see the <code>Č</code> letter in there?). I've tried using both <code>file_get_contents</code> and cURL, none work. Bellow is my non-working code.</p> <p><strong><code>file_get_contents</code>:</strong></p> <pre><code>$url = "http://www.delo.si/assets/media/picture/20121228/POLITIČNI05 tomi lombar.jpg?rev=2"; $stream_context = array('http' =&gt; array( 'method'=&gt;"GET", 'header'=&gt;"Content-Type: text/html; charset=utf-8" )); $image_contents = file_get_contents($url, false, stream_context_create($stream_context)); file_put_contents("image.jpg", $image_contents); </code></pre> <p><strong>cURL:</strong></p> <pre><code>$url = "http://www.delo.si/assets/media/picture/20121228/POLITIČNI05 tomi lombar.jpg?rev=2"; $ch = curl_init($url); $fp = fopen('image.jpg', 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_ENCODING, "UTF-8"); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/html; charset=utf-8")); curl_exec($ch); curl_close($ch); fclose($fp); </code></pre> <p><strong>What "doesn't work" means:</strong> What I meant with "doesn't work is that I get a different picture downloaded than the one I get if I paste the URL in my browser. This site apparently has a fallback picture set up, so if the picture doesn't exist, you get the default one.</p>
 

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