Uploading file from URL


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();
  • Use file_get_contents or curl and write the contents into the file handler instead of get_uploaded_file

  • E.g., hypeEmbed plugin can do it.

     

    You can display your external image w/o uploading of it on your server

    Form input for adding URL to image:

    $input = elgg_view('input/text', array(
        'name' => 'image',
        'value' => _elgg_html_decode($vars['image'])
    ));

     

    View image:

    $image = $market->image;

    echo '<img src=' . $image . '';

     

    Sure, you need add 'image' parameter for 'market' item in saving action