Answer the question
In order to leave comments, you need to log in
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>
public function upload(Request $request)
{
$path = $request->file('image')->store('uploads', 'public');
return view('about.complaint');
}
Route::post('/image/upload', 'about\[email protected]')->name('image.upload');
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
fopen(): Filename cannot be empty
"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"
$path = $request->file('image')->store('uploads', 'public');
Аргументы:
"uploads"
"public"
Answer the question
In order to leave comments, you need to log in
just do not send to Google or documentation, I have already familiarized myself with them.
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' => 'шляпа)']);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question