在Codeigniter中上传带有网址的图片 [英] Uploading image with url address in Codeigniter
问题描述
CodeIgniter上传库仅支持从PC上传图像文件。
CodeIgniter upload library only supports uploading image file from PC.
我正在尝试编写一个代码,使用户可以上传带有图像URL地址的图像。
I am trying to make a code that a user can upload image with image url address.
http://example.com/photo/jake2910.jpg
我只是将此图像地址发送到服务器并上传照片。
I simply send this image address to server and upload the photo.
做到这一点的方法? (相信我,我已经尝试了几天的不同代码。)
Is there a way to do that? (trust me I tried different codes already for few days.)
推荐答案
CI的上传库完全没有必要。您只需使用以下代码即可下载文件:
There is no need in CI's upload library at all. You can simply download the file with this code:
$url = 'http://example.com/photo/jake2910.jpg';
/* Extract the filename */
$filename = substr($url, strrpos($url, '/') + 1);
/* Save file wherever you want */
file_put_contents('upload/'.$filename, file_get_contents($url));
但是请谨慎选择要保存的文件。请记住,即使图像也可能塞满易受攻击的代码。
But be very cautious about what files you are trying to save. Remember that even images can be stuffed with vulnerable code.
这篇关于在Codeigniter中上传带有网址的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!