CodeIgniter Forums
[solved] CI4 request missing POST and FILES data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: [solved] CI4 request missing POST and FILES data (/thread-75284.html)



[solved] CI4 request missing POST and FILES data - jameslittle - 01-21-2020

I've been hitting my head against my keyboard all afternoon trying to figure this out.

I've got a page that has an image uploader. When I post from the page to a plain PHP page, the file uploads as expected. But when I post to my controller function, the POST and FILES data are empty.

I think it might have something to do with where the IncomingRequest is being instantiated, but I can't figure it out. Essentially I have this route for do_upload, like:


PHP Code:
public function do_upload(){
  print_r($this->request->getFile());
  print_r($_FILES);
  print_r($_POST);


Even though I seem to be posting to the page correctly, I get
PHP Code:
Array ( ) Array ( ) Array ( ) 

Meanwhile, $this->request has tons of info... but just nothing I can find about POST or FILES.

Any ideas?

Using CI 4.0.0 rc3

One thing I forgot to mention, I'm using some variable routing here, so I wonder if that is short-circuiting the POST. In my routes, I've got an entry like this:

$routes->add('editor/do_upload/(:any)', 'Editor::do_upload');

The 3rd parameter is an ID that ties the upload back to a database record.


RE: CI4 request missing POST and FILES data - jameslittle - 01-21-2020

Seems dumb to answer my own question, but I did finally figure this out. Apparently the wildcard routing starts a new HTTP request, so the POST and FILES info was getting lost.

When I changed my route to editor/do_upload instead of editor/do_upload/(:any), it started working. I just had to tweak it to pass my URL parameter as a hidden POST field instead.


RE: CI4 request missing POST and FILES data - littlej - 01-22-2020

Hello ! On the contrary, it is a very good idea to post the solutions, when you have them. I do it too. This can always be useful to others ;-)
Another suggestion, you could add [Solved] in the subject of your thread too, so people know that help is not needed anymore :-)