我一直试图弄清楚如何使用以下代码从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();
答案 0 :(得分:4)
试试这个例子:
$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
或者
$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));
答案 1 :(得分:-2)
在linux主机中,您可以尝试
exec("wget ".$_POST['url']);