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

MichalOravec's avatar

It's really interested, actually I don't know what's going on.

MuhammadMaaz's avatar

haha,fair enough,so tell me do i need to send my image data thorough $_Files?

MuhammadMaaz's avatar

okay i read it,so tell me what next should i do?and if it appeals suitable to you then can i share my screen with you so you can better understand what's going on,thanks for your time devotion

MichalOravec's avatar

First thing what you can do is that you split your one method to two different methods. One for get and another to post.

MuhammadMaaz's avatar

u mean i should get my image field with other method?

MuhammadMaaz's avatar

i just tried that code in my controller and it says undefined index:image,while my image field id is iamge,

$target_dir = "uploads/";
              $target_file = $target_dir . basename($_FILES["image"]["name"]);
              $uploadOk = 1;
              $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
              // Check if image file is a actual image or fake image
              if(isset($_POST["submit"])) {
                  $check = getimagesize($_FILES["image"]["tmp_name"]);
                  if($check !== false) {
                      echo "File is an image - " . $check["mime"] . ".";
                      $uploadOk = 1;
                  } else {
                      echo "File is not an image.";
                      $uploadOk = 0;
                  }
              }
Snapey's avatar

in your store method put

dd(['posted', Request::all()]);

cut and paste this.

check what this shows when you post the form.

You need to split your controller first into the get route to show the form and a post route to receive the posted data

If the dump that appears does not contain the data you expect, use the browser network tools to see what is being posted.

MuhammadMaaz's avatar

it gives error

Non-static method Illuminate\Http\Request::all() should not be called statically```
MuhammadMaaz's avatar

can you people send me some code that successfully stores image in database?

MuhammadMaaz's avatar

i have tried this on simple php page and it's working there.

Previous

Please or to participate in this conversation.