I have tried to solve the problem by looking at the answers for the same problem, but their answer didnt' solve my problem
I have this error when i run this:
$image = Image::make(public_path("storage/{$imagePath}"))->fit(1200, 1200);
when I dd the path, this is wht i have:
"C:\Users\USER\MziSpoort\public\storage/uploads/V9SGmLlbg0r21h7y3pVT6w2IvJwQhTD6nkDtvAYO.jpeg"
thanks for your help,
$image = $request->file('image');
$slug = str_slug($request->title);
if (isset($image))
{
$currentDate = Carbon::now()->toDateString();
$imagename = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
$image_resize = Image::make($image->getRealPath());
$image_resize->resize(1600,1066);
if (!file_exists('storage/uploads/post'))
{
mkdir('storage/uploads/post',0777,true);
}
//$image->move('storage/uploads/post',$imagename);
$image_resize->save('storage/uploads/post/'.$imagename);
}else{
$imagename = "default.png";
}
// just use this code, i hope your problem solve
Related
I'm getting photo from Android phone using API and base64encoded format.
After getting photo i must to resize it. But i'm getting error. Please help to solve it.
$image = $request->photo; // my base64 encoded
$image = str_replace('data:image/jpg;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imagename = 'prsn-'.time().'.jpg';
$destinationPath = public_path('/thumbnail');
$img = Image::make($image);
$img->resize(150, 150, function ($constraint)
{
$constraint->aspectRatio();
})->save($destinationPath.'/'.$imagename);
$destinationPath = storage_path('local');
$image->move($destinationPath, $imagename); /*** <<<<<<< getting error on this line ***/
$input = $request->all();
$input['photo'] = $imagename;
Contact::create($input);
Problem is solved using belowed code
$image = $request->photo; // my base64 encoded
$image = str_replace('data:image/jpg;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imagename = 'prsn-'.time().'.jpg';
$destinationPath = public_path('/thumbnail');
$img = Image::make($image);
$img->resize(150, 150, function ($constraint)
{
$constraint->aspectRatio();
})->save($destinationPath.'/'.$imagename);
$destinationPath = public_path('/images');
Image::make($image)->save($destinationPath.'/'.$imagename);
$input = $request->all();
$input['photo'] = $imagename;
Contact::create($input);
Thanks for all who want to help, special thank to: porloscerros-Ψ for advice and suggestion
i am uploading gif for my posts in laravel but gif is like an image its not moving or something like this
<?php
if($request->hasFile('gif')){
$gif = $request->file('gif');
$gif_filename = time() . '.' . $gif->getClientOriginalName();
$gif_location = public_path('/images/' . $gif_filename);
Image::make($gif)->save($gif_location);
}
$post->gif = $gif_filename;
$post->save();
?>
here is the code what I am using I think everything is kinda correct
I use this method
if(Input::hasFile('imagen')) {
$time = Carbon::now()->format('Y-m-d');
$image = $request->file('imagen');
$extension = $image->getClientOriginalExtension();
$name = $image->getClientOriginalName();
$fileName = $time."-".$name;
$image->move(storage_path(),$fileName);
}
Please try this and let me know how it works :)
An easy way to update and save is to do it like this:
public function store(Request $request)
{
$imgLocation = Storage::disk('public')->put(time() . '.' . $request->file('image')->getClientOriginalName(), $request->gif), $request->file('gif'));
// This would save it to the gifs table if you need something like it, otherwise skip this creation
$gif= Gif::create([
'name' => $request->name,
'path' => $imgLocation
]);
if ($gif) {
return response()->json("Success!");
}
return response()->json("Error!"); // or you return redirect()...
}
$image = $request->file('image');
if(isset($image)) {
if($image->getClientOriginalExtension()=='gif'){
$image = $request->file('image');
$extension = $image->getClientOriginalExtension();
$name = $image->getClientOriginalName();
$fileName = 'exerciseimages'."-".$name;
$image->move('storage/courseimages/',$fileName);
}
else{
$fileName = 'exerciseimages'.'-'.uniqid().'.'.$image->getClientOriginalExtension();
if(!Storage::disk('public')->exists('courseimages')){
Storage::disk('public')->makeDirectory('courseimages');
}
$amenitiesimg = Image::make($image)->resize(250,250)->stream();
Storage::disk('public')->put('courseimages/'.$fileName, $amenitiesimg);
}
}
else {
$fileName = 'default.png';
}
and it is saved but the issue is all the images have different auto
increment ids in database i want to save the images with the same ids
which is save at the same time,kindly guide me.
****strong text** the code is below;**
$field = Input::file('image');
$location = public_path('uploads/');
foreach ($field as $k => $fd) {
$filename = str_random(2).'-' . time() . "." . $fd->getClientOriginalExtension();
$fd->move($location , $filename);
$product->image = $filename;
}
$user->save();
I think bellow code helps you..
You can try.
$picture = '';
if ($request->hasFile('image')) {
$files = $request->file('image');
foreach($files as $file){
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$picture = date('His').$filename;
$destinationPath = base_path() . '\public\images';
$file->move($destinationPath, $picture);
}
}
if (!empty($product['images'])) {
$product['images'] = $picture;
} else {
unset($product['images']);
}
Following a tutorial I did this:
public function store(Request $request)
{
$file = Input::file('imagen1');
$image = \Image::make(\Input::file('imagen1'));
$path = public_path().'/thumbnails/';
$image->save($path.$file->getClientOriginalName());
$image->resize(null, 300, function ($constraint) {
$constraint->aspectRatio();
});
$image->save($path.'thumb_'.$file->getClientOriginalName());
$thumbnail = new Thumbnail();
$thumbnail->image = $file->getClientOriginalName();
$thumbnail->save();
$request->user()->propiedades()->create($request->all());
return redirect('profile#propiedades');
}
And my problem is that the image is being save in a "temporal" path and not the real one. So when i go to my table 'Propiedades' It just shows this:
The right direction is this one
So my question is how do i make intervention image saves the real path? Thanks in advance
UPDATE
Ok. Now thanks to Nazmul Hasan i am seeing this in my database.
The only thing left is that it saves the name of the file. So i can go to my blade and do {{ $propiedades->imagen1 }}
Thanks!!
UPDATE 2
$file = Input::file('imagen1');
$ext = time() . '.' . $file->getClientOriginalExtension();
$path = public_path('thumbnails/' . $ext);
$image = \Image::make(\Input::file('imagen1'));
$image->save($path.$file->getClientOriginalName());
$image->resize(400, null, function ($constraint) {
$constraint->aspectRatio();
});
$image->save($path.'thumb_'.$file->getClientOriginalName());
$thumbnail = new Thumbnail();
$thumbnail->image = $file->getClientOriginalName();
$thumbnail->save();
$inputs = $request->all();
$inputs['imagen1'] = $path;
$request->user()->propiedades()->create($inputs);
return redirect('profile#propiedades');
AND NOW IT SAVES RIGHT THE IMG PATH BUT THE IMAGE IS NOT BEING SAVE CORRECLTY
Your problem is in this line
$request->user()->propiedades()->create($request->all());
You does not update image upload path in $request variable
For this reason $request->all() save temporary image path
You can try this
$file = Input::file('imagen1');
$image = \Image::make(\Input::file('imagen1'));
$path = public_path().'/thumbnails/';
$image->save($path.$file->getClientOriginalName());
$image->resize(null, 300, function ($constraint) {
$constraint->aspectRatio();
});
$image->save($path.'thumb_'.$file->getClientOriginalName());
$thumbnail = new Thumbnail();
$thumbnail->image = $path.'thumb_'.$file->getClientOriginalName();
$thumbnail->save();
$inputs = $request->all()
$inputs['imagen1'] = $path.$file->getClientOriginalName();
$request->user()->propiedades()->create($inputs);
return redirect('profile#propiedades');
I want to ask, how can I make that somebody selects an image, then he clicks upload and the image will save into my project (example: project/public/images). Thank you :)
You can just do:
$file = $request->file('image');
$name = $file->getClientOriginalName();
$path = public_path("images/$name");
Storage::put($path, File::get($file->getRealPath()));
However. I would recommend to use laravel medialibrary package:
https://docs.spatie.be/laravel-medialibrary/v4/introduction
This way you can just do:
$post->addMediaFromRequest('image')->toCollection('images');
Or else you can do like this
$destinationPath = '';
$filename = '';
if (Input::hasFile('file')) {
$file = Input::file('file');
$destinationPath = public_path().'/images/';
$filename = time() . '_' . $file->getClientOriginalName();
$filename = str_replace(' ','_',$filename);
$uploadSuccess = $file->move($destinationPath, $filename);
}