0

My problem is following. I'm writing this test data seed file. I already have all functionalities wrote (creating thumbnalins, hd, watermarking img, etc...) so now I would like just to reuse this code, but with some hardcoded image data location.

$imgToUploadLocation = "../../static/img/test.jpg";
$_FILE['userfile'] = imgToUploadLocation;

$config['upload_path'] = '/pictures/';
$config['allowed_types'] = 'jpeg|jpg';
$config['remove_spaces'] = true;
$config['max_size'] = '25000';
$config['encrypt_name'] = true;
$this->upload->initialize($config);
if ($this->upload->do_upload()) {
  echo "finaly!";
} else {
  echo "error";
}

The problem is that however i specify my image location i will always get error you did not select any image to upload.

I wonder how to use upload library without view form? If you need any additional informations please let me know and I will provide. Thank you!

Valor_
  • 3,461
  • 9
  • 60
  • 109

1 Answers1

1

This is not the proper way of defining. Files are expected in a certain way on the $FILES global variable to be uploaded.

In order to define the file you want to upload do:

$_FILES['userfile']['name'] = 'what name you want';
$_FILES['userfile']['tmp_name'] = $imgToUploadLocation;

Read more about the $_FILES in https://secure.php.net/manual/en/features.file-upload.post-method.php

  • 1
    Yes this was it! Now i get error upload path is not valid, but this is whole another story ;) thank you! – Valor_ Feb 27 '18 at 20:48
  • 1
    Valid upload path can be derived from `FCPATH` or './pictures/'. The upload class doesn't create the directory if it doesn't exist so you should see if the dir exists first, and if not do a mkdir otherwise errors. @Valor_ – Alex Feb 27 '18 at 23:25