Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When I run it, PHP gives me the following error:</p> <blockquote> <p>Warning: fwrite() expects parameter 2 to be string, resource given ... on line 53</p> </blockquote> <p><a href="http://php.net/fwrite" rel="nofollow"><code>fwrite()</code></a> writes a string to a file. You want to use the GD function <a href="http://php.net/imagejpeg" rel="nofollow"><code>imagejpeg()</code></a> to save the GD resource to a file. It works for me when I change</p> <pre><code>$fp = fopen($fullpath,'x'); fwrite($fp, $im2); fclose($fp); </code></pre> <p>to</p> <pre><code>imagejpeg($im2, $fullpath); </code></pre> <hr> <p>On an unrelated note, if all you're doing with cURL is grabbing the files, you can simply use <a href="http://php.net/file_get_contents" rel="nofollow"><code>file_get_contents()</code></a> instead of cURL, assuming PHP is configured to allow full URLs in fopen functions. (I believe it is by default.) See the Notes section on <a href="http://php.net/file_get_contents" rel="nofollow">the file_get_contents() manual page</a> for more info. The function <em>is</em> binary-safe, so it works with images in addition to text files. To use it, I just replaced all six lines of the cURL functions with this line:</p> <pre><code>$rawdata = file_get_contents($img); </code></pre> <hr> <p>Update:<br> In response to your question below, you can specify a new file name for them in the array keys like so:</p> <pre><code>&lt;?php $img['img1.jpg']='http://i.indiafm.com/stills/celebrities/sada/thumb1.jpg'; $img['img2.jpg']='http://i.indiafm.com/stills/celebrities/sada/thumb5.jpg'; foreach($img as $newname =&gt; $i){ save_image($i, $newname); if(getimagesize(basename($newname))){ </code></pre>
 

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