D
D
Danila5342020-01-03 23:23:39
Laravel
Danila534, 2020-01-03 23:23:39

Why are files not being saved to disk?

Good evening,
After reading the documentation about file systems, I could not get comfortable ... The bottom line is that when submitting a form with an uploaded image, it does not send it to disk.
Maybe you are in the know, please, just do not send to Google or documentation, I have already familiarized myself with them.

The form itself:

<form action="{{ route('image.upload') }}" method="POST" enctype="multipart/form-data">
     {{ csrf_field() }}
     <div class="form-group">
         <input type="file" name="image" id="image">
         <button class="btn btn-default" type="submit">Загрузка</button>
     </div>
 </form>


Controller:
public function upload(Request $request)
    {
       $path = $request->file('image')->store('uploads', 'public');

       return view('about.complaint');
    }


Route:
Route::post('/image/upload', 'about\[email protected]')->name('image.upload');


filesystems.php
'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],


Error while submitting:
fopen(): Filename cannot be empty

Arguments for uploading:
"uploads"
UploadedFile {#607 ▼
  -test: false
  -originalName: "head555.png"
  -mimeType: "image/png"
  -error: 0
  #hashName: "VvplFvJmBLPRtXD1RWN6lacDnVZwxjJPV93SOZbc"
  path: "C:\Windows\Temp"
  filename: "php98A8.tmp"
  basename: "php98A8.tmp"
  pathname: "C:\Windows\Temp\php98A8.tmp"
  extension: "tmp"
  realPath: false
  aTime: 2021-01-03 23:15:59
  mTime: 2021-01-03 23:15:59
  cTime: 2021-01-03 23:15:59
  inode: 0
  size: 465540
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\Windows\Temp\php98A8.tmp"
}
"VvplFvJmBLPRtXD1RWN6lacDnVZwxjJPV93SOZbc.png"


What does the debugger rely on:
$path = $request->file('image')->store('uploads', 'public');

  Аргументы:
"uploads"
"public"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin B., 2020-01-03
@Kostik_1993

just do not send to Google or documentation, I have already familiarized myself with them.

I'll probably do it anyway)) https://www.google.com/search?q=fopen()%3A+Filenam...

D
Dmitry, 2021-01-04
@DKWLB

Suddenly it will come in handy - this is how my pictures are uploaded. Removed superfluous

if ($request->hasFile('somefile')) {
        $file = $request->file('somefile');
        $path = Storage::disk('public')->put('photos_news', $file);
        // $path = $file->store('news'); // вот такое даже закомментировано... со store не сложилось. через put работает
        if ($file) {
            $fileName = $request->file('somefile')->getClientOriginalName();
            return response()->json(['path' => $path, 'success' => 'есть файл']);
        } else {
            return response()->json(['success' => 'шляпа)']);
        }
    }

P
pLavrenov, 2021-01-04
@pLavrenov

There is... spatie/laravel-medialibrary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question