开发者

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

开发者 https://www.devze.com 2022-12-23 21:43 出处:网络
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.

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

精彩评论

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