CodeIgniter Forums
Upload image from URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Upload image from URL (/showthread.php?tid=53185)



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;
   }
}