Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ropali opened this issue Apr 25, 2020 · 4 comments
Closed

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

ropali opened this issue Apr 25, 2020 · 4 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@ropali
Copy link

ropali commented Apr 25, 2020

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_no="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity_no="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

@ropali ropali added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 25, 2020
@michalsn
Copy link
Member

If in your routes file, you have set the $routes->setAutoRoute(false) then it's a bug. Otherwise, not - because POST request to upload/index is still reachable, even if not defined directly.

@lonnieezell
Copy link
Member

@ropali can you verify your setAutoRoute() value for us, please? That way we know how to move forward.

@ropali
Copy link
Author

ropali commented Apr 27, 2020

$routes->setAutoRoute(true);
This is the way it was set up which is default I guess.I had not changed it at all.

@michalsn
Copy link
Member

Okay, so it's not a bug.

When the auto-route is turned on, all controllers and their methods are reachable. Your declaration in the routes file doesn't stop you from accessing upload/index endpoint by POST request.

Please, read more about it in the user guide.

@ropali ropali closed this as completed Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants