Welcome Guest, Not a member yet? Register   Sign In
Upload image from URL
#1

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




Theme © iAndrew 2016 - Forum software by © MyBB