Skip to content

Bug: I am able to make POST request to a GET route #2880

Description

@ropali

I was just playing with the file upload features in CI4. I have created two routes
1)$routes->get('/', 'Home::index');
where the webpage will display the form to upload a file.
2) $routes->get('/upload', 'Upload::index');
This route will actually handle the file upload mechanism. As you can see it is a GET route(which i had created by mistake).If I make the file upload request to this route then it works perfectly. Should not the framework throw an error to make a POST request to a GET route?
HTML Form

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CI4 - File Upload Demo</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>

<body>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6 mt-5">
                <h1>CI4 - File Upload Demo</h1>
                <form action="<?= base_url('upload')?>" method="POST" enctype="multipart/form-data">
                    <div class="card">

                        <div class="card-body">
                            <h5 class="card-title">Choose File Here</h5>
                            <div class="form-group">

                                <input type="file" class="form-control-file" name="file" id="file">
                            </div>
                            <button class="btn btn-primary">Upload</button>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>

</body>

</html>

Upload Controller

<?php 
namespace App\Controllers;

class Upload extends BaseController
{
	
	public function index()
	{
        $request = $this->request;
        
        $file = $request->getFile('file');
        $file->move(WRITEPATH . 'uploads/', $file->getRandomName());
        
        echo 'File Uploaded Successfully';
    }
    
   
	//--------------------------------------------------------------------


}

Context

  • OS: windows 10

  • Web server Apache/2.4.37 (Win32) OpenSSL/1.1.1a PHP/7.3.0
    --

  • PHP version 7.3.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions