1

I want to upload a photo along with a text

But the photo path is not saved inside the table, but the photo is uploaded to the directory

Controller code

namespace App\Http\Controllers;
use App\Http\Requests\singlereq;
use App\infouser;
class singleupload extends Controller
{
    public function uploadform()
    {
        return view('singleupload.upload_form');
    }
    public function uploadSubmit(singlereq $request)
    {
        $file = $request->file('imgs');
        $file->move('img', $file->getClientOriginalName()); 
        $product = infouser::create($request->all());
        return 'OK Upload successful!';
    }
}
4
  • In the product is the name of the product is imgs Commented Oct 4, 2017 at 19:12
  • The name of the product is And Field img for product Commented Oct 4, 2017 at 19:15
  • 1
    So rename the input file name to img and here to $file = $request->file('imgs'); must be $file = $request->file('img'); and tested !! Commented Oct 4, 2017 at 19:35
  • You should just save the name of the image with extension and when you will access the image for showing purpose, then you can add folder_name/image_name, where image_name will come from database, for better way you can write a function in infouser modal file to fetch the image. Commented Oct 4, 2017 at 19:53

1 Answer 1

1

Used below code. to get the image name and set the table column (your_file) your is column name in your table.

$file = $request->file('imgs');
$file->move('img', $file->getClientOriginalName()); 
$input = $request->all();
$name = $file->getClientOriginalName();
$input['your_file'] = $name; 
$product = infouser::create($input);
return 'OK Upload successful!';
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.