I would like to know the best way to save an image from a URL in php.
At the time I am using
file_put_contents ($ pk, file_get_contents ($ PIC_URL));
Which is not ideal. Is there any way specifically for file I am unable to use curl?
It's okay to use file_gate_contents, as long as the file is not very large, you really There is no need to catch the whole thing in memory.
For large recovery, you can remotely file a file at a time, say it, 32KB, and a loop locally until all files are read.
For example:
$ fout = fopen ('/ tmp / lot generates. JPEG', 'W'); $ Fin = FOPN ("http://www.example.com/verylarge.jpeg", "RB"); While (FIFF ($ Wings)) {$ buffer = Fred ($ fin, 32 * 1024); Fwrite ($ fout, $ buffer); } Fclose ($ feathers); Fclose ($ fout);
(To check the error for simplicity!)
Alternatively, you can skip using and using a class like peer You can use, or use your own HTTP client code etc. . If you keep the cache of remote files, then it enables you to send efficient things like send headers.
Comments
Post a Comment