i have a project that it has some posts on it i have made admin panel to create new posts since i uploaded my project on cpanel host i can create a post but image wont shown in my post but before that on my localhost i can craete a post and store image in my path i checked my public path in my host and saw that there isn,t any new image related to my post that i have created with my admin panel on my host just my image name has saved in my database
this is my blog blade file
<section >
<div >
<div >
@foreach($posts as $post)
<div >
<div >
<a href="{{route('blog.single',['title'=>$post->title])}}"> <img src="{{asset('image/'.$post->header_image)}}" alt="{{$post->title}}" ></a>
<div >
<a href="{{route('blog.single',['title'=>$post->title])}}">
{{str_replace('_',' ',$post->title)}}
</a>
<p >
{!! strip_tags(mb_substr($post->content,0,270,'utf-8')) !!} ...
</p>
<div >
<p ><i ></i> {{$post->time}} دقیقه</p>
</div>
</div>
</div>
</div>
@endforeach
</div>
</div>
</section>
this is my postcontroller codes
public function storeImage(Request $request)
{
$image_name = null;
if ($request->file('image')) {
$image = $request->file('image')->getClientOriginalName();
$image_name = time() . $image;
$folder = public_path('/image');
$path = $folder . '/' . $image_name;
if (is_dir($folder)) {
$img = Image::make($request->file('image'))->resize(500, 438);
$img->save($path);
} else {
File::makeDirectory($folder, 0755, true);
$img = Image::make($request->file('image'))->resize(500, 438);
$img->save($path);
}
}
return $image_name;
}
this code works great in my localhost server but when i uploaded it on host i think image intervation wont work
CodePudding user response:
You have to set the symlink to connect the stroge folder with the public folder.
Try running php artisan storage:link
on the webserver.
Also in some hostings this command is banned. In that case you have to create the symlink manually using forexample midnight commander.
CodePudding user response:
Try with 777 permission for make directory.
File::makeDirectory($folder, 0777, true);