php - Error 0 byte when save image to local or other server -


function grab_image($url, $saveto){         $url = $url;         $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)){             unlink($saveto);         }         $fp = fopen($saveto, 'w');         fwrite($fp, $raw);         fclose($fp);     } $link = 'https://images-na.ssl-images-amazon.com/images/i/415lkujc%2b2l.jpg'; grab_image($link, '/tmp/415lkujc%2b2l.jpg'); 

error when save local file (0 byte), think link have special character %2b

try adding file name in function call, following:

grab_image($link, "/tmp/new_file_name.jpg"); 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -