开发者

best php method of getting images from a url and saving?

I want to allow users to put in am img url instead of uploadin开发者_如何学JAVAg an image, the image would then go through my thumbnailing class.

Is file_put_contents the best method?


Yep, you can get the contents of a file given its url using file_get_contents, and then just write that to disk, or pass the contents to your thumbnail class to save. There might be safe_mode restrictions on this, but usually it's fine.


file_get_contents will work fine for pulling an external image.

Just bare in mind that some hosts put restrictions on fopen and fopen's wrappers (like file_get_contents and file_put_contents). These can be an all out block on fopen or restricting what it can access (like external files).


Beware of security implications!!! If you aren't careful, users will be able to put ARBITRARY STUFF on your server - including an evil PHP script, renamed as an image! All that they'll have to do to pwn your server when that's done is to rename the file to .php... Be careful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜