<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Session;
use Image;
class gallerycontroller extends Controller
{
//
public function admin_gallery(){
$galleries=DB::Table('galleries')->get();
return view('admin.gallery.list',array('galleries'=>$galleries));
}
public function add_gallery(){
return view('admin.gallery.add');
}
public function insert_gallery(Request $request){
$supported_image = array(
'gif',
'jpg',
'jpeg',
'png',
'jfif'
);
$data=array(
'title'=>$request['title'],
);
$gallery_id=DB::Table('galleries')->insertGetId($data);
$files = $request->file('images');
if ($files) {
foreach($files as $file){
$type="";
$imagescount=0;
$videoscount=0;
$random= rand(10,100);
$input['filename'] = $random. time().'.'.$file->getClientOriginalExtension();
if (in_array($file->getClientOriginalExtension(), $supported_image)) {
$type="Image";
$imagescount=DB::Table('galleries_attachments')->where('type','Image')->get();
$imagescount=count($imagescount);
if($imagescount>100){
Session::flash('msg2', 'You Have Exceeded Your 100 Image Upload Limit');
return redirect('admin_gallery');
}
$destinationPath = ('public/uploads/gallery/');
$img = Image::make($file->getRealPath());
$img->resize(650, 650, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['filename']);
$destinationPath =('public/uploads/gallery/');
$file->move($destinationPath, $input['filename']);
$name= $input['filename'];
} else {
$videosize=$file->getClientSize();
$file_size = 0;
$file_size = number_format($videosize / 1048576,2);
if($file_size>'60.00'){
Session::flash('msg2', 'The Video Upload Size is greater then 60MB');
return redirect('admin_gallery');
}
$videoscount=DB::Table('galleries_attachments')->where('type',"")->get();
$videoscount=count($videoscount);
if($videoscount>10){
Session::flash('msg2', 'You Have Exceeded Your 10 Videos Upload Limit');
return redirect('admin_gallery');
}
$file->move('public/uploads/gallery/',$input['filename']);
$name= $input['filename'];
}
$data=array([
'image_name'=>$name,
'gallery_id'=>$gallery_id,
'type'=>$type
]);
DB::table('galleries_attachments')->insert($data);
}
}
else{
// echo "WE dont have any thing";
}
// echo "I am here after";
// exit();
Session::flash('msg', 'Gallery has been added');
return redirect('admin_gallery');
}
public function edit_gallery($gallery_id){
$galleries=DB::Table('galleries')->where('gallery_id',$gallery_id)->get();
return view('admin.gallery.edit',array('galleries'=>$galleries));
}
public function update_gallery(Request $request){
$data=array(
'title'=>$request['title'],
);
DB::Table('galleries')->where('gallery_id',$request['gallery_id'])->update($data);
Session::flash('msg', 'Gallery has been Updated');
return redirect('admin_gallery');
}
public function delete_gallery($id){
DB::Table('galleries')->where('gallery_id',$id)->delete();
$images=DB::Table('galleries_attachments')->where('gallery_id',$id)->get();
foreach($images as $image){
unlink('public/uploads/gallery/'.$image->image_name);
}
DB::Table('galleries_attachments')->where('gallery_id',$id)->delete();
Session::flash('msg2', 'Gallery has been Deleted' );
return back();
}
public function delete_gallery_image($id){
$images=DB::Table('galleries_attachments')->where('attachment_id',$id)->get();
foreach($images as $image){
unlink('public/uploads/gallery/'.$image->image_name);
}
DB::Table('galleries_attachments')->where('attachment_id',$id)->delete();
Session::flash('msg2', 'Image has been Deleted' );
return back();
}
public function edit_gallery_images($id){
$images= DB::Table('galleries_attachments')->where('gallery_id',$id)->get();
return view('admin.gallery.edit_gallery_images',array('images'=>$images,'gallery_id'=>$id));
}
public function add_gallery_images($gallery_id){
return view('admin.gallery.add_gallery_images',array('gallery_id'=>$gallery_id));
}
public function insert_gallery_images(Request $request){
$supported_image = array(
'gif',
'jpg',
'jpeg',
'png',
'jfif'
);
$gallery_id=$request['gallery_id'];
$files = $request->file('images');
if ($files) {
foreach($files as $file){
$type="";
$random= rand(10,100);
$input['filename'] = $random. time().'.'.$file->getClientOriginalExtension();
if (in_array($file->getClientOriginalExtension(), $supported_image)) {
$type="Image";
$imagescount=DB::Table('galleries_attachments')->where('type','Image')->get();
$imagescount=count($imagescount);
if($imagescount>100){
Session::flash('msg2', 'You Have Exceeded Your 100 Image Upload Limit ');
return redirect('admin_gallery');
}
$destinationPath = ('public/uploads/gallery/');
$img = Image::make($file->getRealPath());
$img->resize(650, 650, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['filename']);
$destinationPath =('public/uploads/gallery/');
$file->move($destinationPath, $input['filename']);
$name= $input['filename'];
} else {
$videosize=$file->getClientSize();
$file_size = 0;
$file_size = number_format($videosize / 1048576,2);
if($file_size>'60.00'){
Session::flash('msg2', 'The Video Upload Size is greater then 60MB');
return redirect('admin_gallery');
}
$videoscount=DB::Table('galleries_attachments')->where('type',"")->get();
$videoscount=count($videoscount);
if($videoscount>10){
Session::flash('msg2', 'You Have Exceeded Your 10 Videos Upload Limit');
return redirect('admin_gallery');
}
$file->move('public/uploads/gallery/',$input['filename']);
$name= $input['filename'];
}
$data=array([
'image_name'=>$name,
'gallery_id'=>$gallery_id,
'type'=>$type
]);
DB::table('galleries_attachments')->insert($data);
}
}
Session::flash('msg', 'Gallery has been Updated');
return redirect('edit_gallery_images/'.$gallery_id);
}
public function edit_gallery_image($id){
$image=DB::Table('galleries_attachments')->where('attachment_id',$id)->get();
return view('admin.gallery.edit_gallery_image',array('image'=>$image));
}
public function update_gallery_single_image(Request $request){
$supported_image = array(
'gif',
'jpg',
'jpeg',
'png',
'jfif'
);
$file = $request->file('image');
$random= rand(10,100);
$input['filename'] = $random. time().'.'.$file->getClientOriginalExtension();
if (in_array($file->getClientOriginalExtension(), $supported_image)) {
$type="Image";
$destinationPath = ('public/uploads/gallery/');
$img = Image::make($file->getRealPath());
$img->resize(650, 650, function ($constraint) {
$constraint->aspectRatio();
})->save($destinationPath.'/'.$input['filename']);
$destinationPath =('public/uploads/gallery/');
$file->move($destinationPath, $input['filename']);
$name= $input['filename'];
}else{
$videosize=$file->getClientSize();
$file_size = 0;
$file_size = number_format($videosize / 1048576,2);
if($file_size>'60.00'){
Session::flash('msg2', 'The Video Upload Size is greater then 60MB');
return redirect('admin_gallery');
}
$file->move('public/uploads/gallery/',$input['filename']);
$name= $input['filename'];
}
$data=array(
'image_name'=>$name
);
DB::Table('galleries_attachments')->where('attachment_id',$request['attachment_id'])->update($data);
Session::flash('msg', 'Gallery has been Updated');
return redirect('admin_gallery');
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]