Question

I've been trying to figure out how to upload a file from a URL using the following code without using a form. In a form I can enter in a URL instead of a local file on the computer and it uploads it, So im guessing its possible?:

example location: 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();

No correct solution

OTHER TIPS

Try this example:

Saving image from PHP URL

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

or this

$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));

In linux hosts you can try

exec("wget ".$_POST['url']);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top