Laravel 5.4 file upload
You should try this:
The form data being encoded as “multipart/form-data”
, which is required when files will be included as form data.
<form action="{{ route('my-url') }}" method="post" enctype="multipart/form-data">
<input type="file" name="pic">
</form>
Laravel 5.4: How to upload an image to the server with the user that uploaded it?
You're creating the Photo with only a title and image. Needs a user_id param.
$input['title'] = $request->title;
$input['user_id'] = $user;
Photos::create($input);
Or
Auth::user()->photos()->create($input);
Image upload not work laravel 5.4 doesn't get any error
add enctype="multipart/form-data"
to your form
tag:
<form class="form-horizontal" enctype="multipart/form-data" role="form" action="{{ route("karyawan.store") }}" method="post" multiple>
{{ csrf_field() }}
<div class="row">
<!-- left column -->
<div class="col-md-3">
<div class="text-center">
<img src="//placehold.it/100" class="avatar img-circle" alt="avatar">
<h6>Upload a different photo...</h6>
<input type="file" name="photo" class="form-control" />
</div>
</div>
</form>
Laravel 5.4 file uploading error - fileName not uploaded due to an unknown error
First only using time()
method won't work to generate unique file name for all three images all the time and when a concurrent request occurs.
Second:
$names = [ $name , $name_575 , $name_768];
foreach ( $names as $n){
$file->move('uploads/banners/',$n);
}
What you are looping is totally wrong. You are trying to move the same image, $file for three times.
You have to move all the three images inside the loop:
`
$file = $request->image;
$file_575 = $request->image_575;
$file_768 = $request->image_768;
`
So, you should probably do:
$filesToMoves = [$name=> $file, $name_575 => $file2 , $name_768 => $file3];
foreach($filesToMoves as $fileName => $fileToMove){
$fileToMove->move('uploads/banners/',$fileName);
}
Related Topics
Codeigniter - File Upload Required Validation
Symfony\Component\Httpkernel\Exception\Notfoundhttpexception Laravel
PHP Remove Elements from Associative Array
Understanding PHP Curl_Multi_Exec
Which Method Is Preferred Strstr or Strpos
Should Lock_Ex on Both Read & Write Be Atomic
Finding Free Blocks of Time in MySQL and PHP
Do PHP Pdo Prepared Statements Need to Be Escaped
PHP Adding Custom Namespace Using Autoloader from Composer
MySQL Stored Procedure VS. Complex Query
Sending and Receiving Data from Flash As3 to PHP
How to Use Authentication for Multiple Tables in Laravel 5