ob get contents - Sometimes my PHP function doesn't work well -


i wrote php function copy internet image local folder, works well, generate invalid file size of 1257b.

function copyimagetolocal($url, $id) {     $ext=strrchr($url, ".");      $filename = 'images/' . $id . $ext;      ob_start();      readfile($url);      $img = ob_get_contents();      ob_end_clean();      $fp=@fopen($filename, "a");      fwrite($fp, $img);      fclose($fp);  } 

note: $url passed in valid, function fails @ first time, may successful second or third time. it's strange... require special php settings?

please me!


i have found real reason: test image url not allowed program accessing, though can opened in browser. tried other image url, function works well.

so, seems need find way process kind of cases. guys!

why don't open file , write disk so:

file_put_contents($filename, fopen($url, 'r')); 

this buffering shouldn't run memory problems (since storing whole image in memory before writing file)


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -