【发布时间】:2014-04-02 21:06:47
【问题描述】:
我一直在尝试弄清楚如何在不使用表单的情况下使用以下代码从 URL 上传文件。在一个表单中,我可以输入一个 URL 而不是计算机上的本地文件,然后它会上传它,所以我猜它可能吗?:
示例位置:http://www.bubblews.com/assets/images/news/521013543_1385596410.jpg
if ((isset($_FILES['upload']['name'])) && (substr_count($_FILES['upload']['type'],'image/'))) {
$prefix = "market/".$market->guid;
$filehandler = new ElggFile();
$filehandler->owner_guid = $market->owner_guid;
$filehandler->setFilename($prefix . ".jpg");
$filehandler->open("write");
$filehandler->write(get_uploaded_file('upload'));
$filehandler->close();
【问题讨论】:
-
听起来像是你应该使用 curl 的东西。
-
将远程文件下载到您的服务器(也称为 URL 上传)与本地文件上传非常不同。可以在此处找到使用 curl 的良好解决方案:stackoverflow.com/questions/6348602/…
标签: php image forms file upload