Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Abrar_ul_Hassan's avatar

ERROR 404 NOT FOUND

UI form code

<h3 class="text-center mb-4">Chefs Information</h3>

<!-- Name -->
<div class="mb-3">
    <label for="name" class="form-label">Chef Name</label>
    <input type="text" class="form-control" id="name" name="name" placeholder="Enter chef's name" required>
</div>

<!-- Speciality -->
<div class="mb-3">
    <label for="speciality" class="form-label">Speciality</label>
    <input type="text" class="form-control" id="speciality" name="speciality" placeholder="Enter speciality" required>
</div>

<!-- Image Upload -->
<div class="mb-3">
    <label for="image" class="form-label">Image</label>
    <input type="file" class="form-control" id="image" name="image" accept="image/*" required>
</div>

<!-- Submit Button -->
<div class="text-center"> 
    <button type="submit" class="btn btn-primary px-4 py-2">
        Save Chef
    </button>
</div>

UserController Code function ChefUpload

public function storechef(request $request)
{
    if($request->hasFile('image'))
    {
        $image = $request->file('image');
        $imageName = time().'.'.$image->getClientOriginalExtension();
        $image->move(public_path('chefsUpload'),$imageName);
        Chefs::create([
            'name'=>$request->name,
            'speciality'=>$request->speciality,
            'image'=>$imageName
        ]);
        return redirect()->route('storechef')->with('success','Chefs Store Successfully');
    }
}

Route Web Routes

use App\Http\Controllers\userController;
Route::post('/chefsUpload', [userController::class,'storechef']);

Error I am getting Not Found The requested resource /chefsUpload was not found on this server. on Route http://127.0.0.1:8000/chefsUpload

Help me Solve this error

0 likes
4 replies
jj15's avatar
jj15
Best Answer
Level 10

Your route (/chefsUpload) is named the same as the directory in /public where you're storing the uploaded images. You'll need to either change the route path or the name of the directory.

Additionally:

  • It may not be the best idea to store user-uploaded images in the public folder, since if you ever push your project to version control (such as on GitHub), those files will stay. You'll want to use Laravel's built-in storage system instead.

  • It's unsafe to use getClientOriginalExtension() as it could allow someone to execute arbitrary code on your server. Use extension() instead.

  • In your route action, [userController::class,'storechef'], don't use camelCase for the controller class name, it should be PascalCase. The controller method should be camelCase though.

1 like
Abrar_ul_Hassan's avatar

@jj15 Thanks Brother, you are legend. You solve my problem. I am thankful to you!

1 like
jlrdw's avatar

To add what @jj15 said check these out:

https://symfonycasts.com/screencast/symfony-uploads/file-naming#play

https://symfonycasts.com/screencast/symfony-uploads/upload-in-form#play

Also if you need to secure user files and images, there are good past post where myself and others explain techniques for this.

As far as getClientOriginalExtension() I would suggest following @jj15 advise strongly.

When I tested this, it is easy to slip php and python code in to do something. I did not test other languages, but I'm sure others can be put in as well.

Research this for yourself.

Edit:

I also suggest: https://laracasts.com/series/30-days-to-learn-laravel-11

2 likes

Please or to participate in this conversation.