0

WHen uploading, all data is inserted in table except pic_path column contains 0. Am i doing wrong when processing file uploaded:

This is the controller:

if(Session::has('userLogged'))
        {
            if($_POST)
            {
                $file;
                if (Input::hasFile('pic'))
                {

                    $file = Input::file('pic');
                    print_r($file);
                }

                $validator = $this->validate(Input::all(), $rules);

                if ($validator != null)
                {

                    return Redirect::to('basicDetails')->withErrors($validator);

                }else{

                    $title = Input::get('title');
                    $summary = Input::get('summary');
                    $description = Input::get('description');
                    $destinationPath = base_path() . '/public/img';
                    $file->move($destinationPath);
                    $path = $file->getRealPath();
                    $personModel = new Course;
                    $personeModel->basicDetails($title, $summary, $description, $path);
                }

and this is form url:

{{ Form::open(array('action' => 'PersonController@basic','files' => true)) }} 

Thanks,

1 Answer 1

1

Before move the file get the path:

$title = Input::get('title');
$summary = Input::get('summary');
$description = Input::get('description');
$destinationPath = base_path() . '/public/img';


$path = $file->getRealPath();

$file->move($destinationPath);


$personModel = new Course;
$personeModel->basicDetails($title, $summary, $description, $path);

I am not sure why you need uploaded path? Usually this is the temp path where Laravel uploaded the file.

http://laravel.com/docs/requests#files

Sign up to request clarification or add additional context in comments.

2 Comments

Aha didn't know it was only temp path. What path should I store to load the picture from later in <img>? is it destinationPath above?
Yes, its destination path. However, You need image file name as well. So, destinationPath + filename.jpg.

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.