Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Permission issue writing image to localhost
    primarykey
    data
    text
    <p>I am getting an error using curl to download an image to my localhost. I've made sure the permissions are good and the directory exists. I'm at a loss for what to check next. This is the error I'm getting</p> <pre><code>Warning: unlink(images/) [function.unlink]: Operation not permitted in /Applications/MAMP/htdocs/test/image/instapaper.php on line 47 </code></pre> <p>Here is my code:</p> <pre><code> $saveto = 'images/'; if ( !file_exists($saveto) ) { mkdir ($saveto, 0777, true); } $url = 'http://img.ffffound.com/static-data/assets/6/4dea2e91338b67cd926140acde1962403c3bf4c2_m.jpg'; echo getcwd() . "\n"; $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $raw=curl_exec($ch); curl_close ($ch); if(file_exists($saveto) &amp;&amp; is_writable($saveto)){ unlink($saveto); } $fp = fopen($saveto,'x'); if(fwrite($fp, $raw)==false){ echo 'no dice'; return; } fclose($fp); </code></pre> <p>**SOLVED</p> <p>Below is the working code. It basically looks like I was trying to save the image as the directory location I had specified. That's been cleared up and I've got an image name provided to save the file to. In the final script the image name will be taken from the url.</p> <pre><code> $url = 'http://img.ffffound.com/static-data/assets/6/4dea2e91338b67cd926140acde1962403c3bf4c2_m.jpg'; $saveto = 'images/'; $image_name = 'image.jpg'; $full_path = $saveto . $image_name; if ( !file_exists($saveto) ) { mkdir ($saveto, 0777, true); } $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $raw=curl_exec($ch); curl_close ($ch); if(file_exists($full_path) &amp;&amp; is_writable($full_path)){ unlink($full_path); } $fp = fopen($full_path,'x'); if(fwrite($fp, $raw)==false){ echo 'no dice'; return; } fclose($fp); </code></pre>
    singulars
    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.
 

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