Reputation: 319
I am trying to add a profile image upload in Laravel 5.1. I used the Intervention/Image
Package but when I try to upload the image I get this error:
NotReadableException in AbstractDecoder.php line 302: Image source not readable
This is my PhotoController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Image;
use Input;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class PhotoController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$img = Image::make($request->file('photo'));
$img->save('image.png');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {}
}
This is my html form:
<header>
<div class="student_profile_sub_header w100">
<div class="container ccenter">
<div class="student_profile_name">
<h4>{{$student->name}} {{$student->surname}}</h4>
</div>
<div class="student_profile_image">
<img src="{{asset('assets/profile_image.png')}}">
</div>
<form method="POST" action="../student/profile/imageupload">
{!! csrf_field() !!}
<input type="file" name="photo">
<input type="submit" value="Upload Image" name="submit">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</form>
</div>
</div>
</header>
Upvotes: 28
Views: 93859
Reputation: 4762
This is not to answer the OP's question, but to answer someone else's who is here with the same question in a different context.
If you are using the File System method like storeAs()
then you are actually uploading your file under /storage/app/public/
from /public/
scope. If so, you will need to run the following command:
php artisan storage:link
This command will create a shortcut link to the /storage
directory under /public
directory, and things should work normally.
I faced a situation where I did not have any SSH access to the server and I could not upload a symlink to the cPanel, I made a temporary route like the one below and hit it once:
Route::get('/symlink', function() {
Artisan::call('storage:link');
echo "Storage Symbolink link is created<br>";
});
When I was done, I removed the route. :)
Upvotes: 18
Reputation: 13
It was
$img=Image::make('photo')->resize(300, 200);
I changed it to
$img=Image::make($request->file('photo'))->resize(300, 200);
And work for me.
Upvotes: -1
Reputation: 89
in my case, the image does not exist in its path, while putting the laravel intervention code. Make sure your image exists in that path.
Upvotes: 0
Reputation: 21
$filenamewithextension = $picture->getClientOriginalName();
$filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
$extension = $picture->getClientOriginalExtension();
$thumbnail = $filename . '_thumbnail_' . time() . '.' . $extension;
$original_picture = $filename . '_original_' . time() . '.' . $extension;
$picture->storeAs('public/profile_images', $original_picture);
$picture->storeAs('public/profile_images/thumbnail', $thumbnail);
$thumbnailpath = public_path('storage/profile_images/thumbnail/' . $thumbnail);
$this->createThumbnail($thumbnailpath, 150, 93);
$picture_path = public_path('storage/profile_images/' . $original_picture);
$this->createThumbnail($picture_path, 550, 340);
$profile_pic = new Profile_Picture();
$profile_pic->user_id = Auth::user()->id;
$profile_pic->picture_path = $original_picture;
$profile_pic->thumbnail = $thumbnail;
$profile_pic->default = 0;
$profile_pic->isVerified = 1;
$profile_pic->save();
Also check that your corresponding paths are correct , that is the image path where you are storing the image and where you are fetching the image from are simmilar
Upvotes: 0
Reputation: 435
Add the following parameter in your form tag:
enctype="multipart/form-data"
And change for this in make:
$img = Image::make($request->file('photo')->getRealPath());
Upvotes: 32
Reputation: 599
Try using laravel collective, Make sure you have checked files to true if you are using laravel collective
{{ Form::open(['route'=>'your-route', 'class'=>'form',**'files'=>true**]) }}
{{ Form::close()}}`
, then when requesting your file in store function add the getRealPath() like this Image::make(Input::file('artist_pic')->getRealPath())->resize(120,75);
Upvotes: 3