CodeIgniter Forums
Upload image from URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Upload image from URL (/thread-53185.html)



Upload image from URL - El Forum - 07-13-2012

[eluser]cyberjunkie[/eluser]
Is it possible to use the File Uploading Class to upload images from a URL? I'm trying to use a callback but it expects a file to be selected from the computer.

In callback


Code:
function _url_upload($str) //$str is text input value, a URL string
{
   // Failed attempt, trying to load file from URL
   $img = file_get_contents($str);
   $_FILES['userfile'] = $img;
  
  
   $config['upload_path'] = "./uploads";
   $config['allowed_types'] = 'jpg|png';
   $config['encrypt_name'] = TRUE;
   $config['overwrite'] = FALSE;
   $config['max_size'] = '800'; //in KB
  
   $this->load->library('upload', $config);
  
   if (! $this->upload->do_upload())
   {
    //set file errors
    $this->form_validation->set_message('_file_validation', $this->upload->display_errors('', ''));
    return FALSE;
   }
   else
   {  
    return TRUE;
   }
}