Skip to content

Instantly share code, notes, and snippets.

@duwaljyoti
Last active September 5, 2016 18:10
Show Gist options
  • Save duwaljyoti/d90a67809fee87ae2c6eaf0cbc061f82 to your computer and use it in GitHub Desktop.
Save duwaljyoti/d90a67809fee87ae2c6eaf0cbc061f82 to your computer and use it in GitHub Desktop.
case "4" :
$extension = \Input::file('product_category_csv')->getClientOriginalExtension();
$filename = strtotime(\Carbon\Carbon::now()) . '_' . mt_rand(0, 99999) . '.' . $extension;
\File::put(public_path("media/" . $filename), \File::get(\Input::file('product_category_csv')));
$counter= 0;
if(($handle = fopen(public_path().'/media/'.$filename,"r"))!==FALSE)
{
fgetcsv($handle);
while(($data = fgetcsv($handle,1000,","))!==FALSE)
{
\DB::statement('SET FOREIGN_KEY_CHECKS = 0');
$original_filename = $data[2];
$filename_with_loc = "/var/www/html/fdw.conceptdev/app/storage/tmp/".$data[2];
$filename = \Carbon\Carbon::now()->timestamp.'.'.$this->cleanFileName(basename($original_filename));
if(file_exists($filename_with_loc))
{
$latest_media_id = \Fdw\Core\Models\Media::whereRaw('id = (select max(`id`) from media)')->get()->first()->id;
// dd($latest_media_id);
$new_folder_id = $latest_media_id+1;
$latest_id = $latest_media_id ;
$old_mask = umask(0);
mkdir("media/".$new_folder_id, 0777) ;
// base_path("app/storage/tmp/".$data[2]) ,
copy(storage_path('tmp/'.$data[2]) , public_path('media'.$new_folder_id."/".$filename));
// copy('/app/storage/tmp/'.$data[2], '/public/media/'.$new_folder_id.'/'.$filename);
$media = new \Fdw\Core\Models\Media ;
$media->user_id = 1;
$media->mime = "image/jpeg";
$media->type = "images";
$media->extension = $extension;
$media->file = $filename;
$media->title =$original_filename;
$media->status = 1;
$media->save();
umask($old_mask);
}
else
echo "doesnot exist";
$current_category = \Fdw\Cart\Models\Category::where("slug",lcfirst($data[1]))->get()->first()
->update(["media_id" => $new_folder_id]);
\DB::statement('SET FOREIGN_KEY_CHECKS = 1');
}
}
else
{
echo "not handled properlyu";
}
/* return \Redirect::back()->with('message', "categories Images deleted and restored");
break;*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment