3

I guys I read the documentation for do a upload file in laravel... But I don't understand more it (I'm beginner) It's my image.blade.php

{{Form::open(['url'=>'administrator/store ', 'files' => true])}} 
{!!Form::file('image') !! } 
{!! Form::submit('next')!!} 
{{Form::close()}} 

Administrator Controller

use Storage; 
use Illuminate\Http\Request; 
use App\Http\Controllers\Controller; 

public function store(Request $request) {
Storage::put($request->image, 'test') ;
} 

I don't understand what I will put into the function..... Help me pls... Greetings!

5
  • 1
    what is the real question? Commented Aug 31, 2016 at 0:46
  • I don't understand how I will do upload my file after I link it by the form... What I will do insert into the function for take and upload the file? These I write into the fuction doesn't work! Commented Aug 31, 2016 at 0:47
  • These what, and define "doesn't work". Commented Aug 31, 2016 at 0:57
  • After the Storage::put the file doesn't store into the path "Storage/app/test" Commented Aug 31, 2016 at 1:00
  • youtu.be/Q6iL3u4IZgs Commented Jun 21, 2020 at 10:34

1 Answer 1

5

\Illuminate\Http\Request::file() is what you have when you're uploading files.

This is just a instance of \Symfony\Component\HttpFoundation\File\UploadedFile class so you can move file to destination/storage what you want, something like that:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class MainController extends Controller
{
    public function upload(Request $request)
    {
        /**
         * @var \Symfony\Component\HttpFoundation\File\UploadedFile
         */
        $uploadedFile = $request->file('image'); 
        
        if ($uploadedFile->isValid()) {
            $uploadedFile->move(destinationPath, $fileName);
        }
    }

}

Aso, you've been used \Illuminate\Filesystem\Filesystem::put() in a wrong way. Below is like that method is implemented:

/**
     * Write the contents of a file.
     *
     * @param  string  $path
     * @param  string  $contents
     * @param  bool  $lock
     * @return int
     */
    public function put($path, $contents, $lock = false)
    {
        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
    }
Sign up to request clarification or add additional context in comments.

Comments

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.