MWDeveloper's avatar

file upload not saved to the database

i want to check if the form post an attachment and save it to the database as well as moving the file to the files folder. I get the following error The file "C:\xampp\tmp\php417C.tmp" does not exist" (The file is moved but the attachment column in messages table is empty)

    $message = new message;

    if($request->hasFile('attachment')){
      $message = new message;
      $attachment = $request->file('attachment');
      //create a file path
      $path = public_path('/uploads/files/');
      //get the file name
      $filename = time() . '.' . $attachment->getClientOriginalExtension();
      //save the file to my path
      $attachment->move($path , $filename);
      

//save that to your database $message->attachment = $pathname;

      $message->save();
    };
0 likes
3 replies
MWDeveloper's avatar

everything is saved to the database but still receiving the error "C:\xampp\tmp\php417C.tmp" does not exist"

Snapey's avatar
$message->attachment = $pathname;

You don't set $pathname?

When do you get the error? On what line?

1 like
MWDeveloper's avatar
MWDeveloper
OP
Best Answer
Level 4

I fix that thank you @Snapey for your reply . the $message->save(); wasn't in the right order so i run it outside if statement and immediately after I affected the input fields's request to the object variables. and that works fine.

Please or to participate in this conversation.