1

CodeIgniter 上传库只支持从 PC 上传图片文件。

我正在尝试制作一个代码,用户可以使用图像 url 地址上传图像。

http://example.com/photo/jake2910.jpg

我只需将此图像地址发送到服务器并上传照片。

有没有办法做到这一点?(相信我,我已经尝试了几天不同的代码。)

4

2 回答 2

7

CI的上传库根本不需要。您可以使用以下代码简单地下载文件:

$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));

但要非常小心您要保存的文件。请记住,即使是图像也可能塞满易受攻击的代码。

于 2012-05-29T08:15:33.963 回答
3

试试这个

copy('http://example.com/photo/jake2910.jpg', '/mylocation/jake2910.jpg');

有关更多详细信息,您可以查看此类似帖子

通过 HTTP 从远程服务器复制图像

于 2012-05-29T08:04:01.783 回答