diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 794b7d8..8051802 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers; +use App\Container; +use App\File; use App\Item; use App\Event; use Illuminate\Http\Request; @@ -44,9 +46,16 @@ class ItemController extends Controller public function create($event, Request $request) { $eid = Event::where('slug','=',$event)->first()->eid; - $data = $request->all(); - $data['eid'] = "".$eid; - $item = Item::create($data); + $newitem = $request->except(['dataImage']); + $newitem['eid'] = "".$eid; + $newitem['item_uid'] = "".rand(10, 100); + $newitem['wo'] = ""; + $item = Item::create($newitem); + $dataImage = $request->get('dataImage'); + $hash = md5(time()); + mkdir('staticimages'); + file_put_contents('staticimages/'.$hash, base64_decode($dataImage)); + $file = File::create(array('hash' => $hash, 'iid'=> $item['iid'])); return response()->json($item, 201); } @@ -62,6 +71,6 @@ class ItemController extends Controller { $eid = Event::where('slug','=',$event)->first()->eid; Item::where('eid', $eid)->where('item_uid', $id)->first()->delete(); - return response()->json(array("satus"=>'Deleted Successfully'), 200); + return response()->json(array("status"=>'Deleted Successfully'), 200); } } diff --git a/public/thumbnail.php b/public/thumbnail.php index c9c3fd5..d3d06b9 100644 --- a/public/thumbnail.php +++ b/public/thumbnail.php @@ -11,14 +11,19 @@ $quality = 90; $thumb = getcwd() . $_GET["id"]; $img = str_replace("thumbnails", "staticimages", $thumb); if (is_file($img)) { - $imagick = new Imagick($img); - $imagick->setImageFormat('jpeg'); - $imagick->setImageCompression(Imagick::COMPRESSION_JPEG); - $imagick->setImageCompressionQuality($quality); - $imagick->cropThumbnailImage($width, $height); - $imagick->setImagePage(0, 0, 0, 0); - if (file_put_contents($thumb, $imagick) === false) { - log_error("Could not put contents."); + try { + $imagick = new Imagick($img); + $imagick->setImageFormat('jpeg'); + $imagick->setImageCompression(Imagick::COMPRESSION_JPEG); + $imagick->setImageCompressionQuality($quality); + $imagick->cropThumbnailImage($width, $height); + $imagick->setImagePage(0, 0, 0, 0); + if (file_put_contents($thumb, $imagick) === false) { + log_error("Could not put contents."); + } + }catch(Exception $exception){ + log_error($exception); + $imagick = file_get_contents($img); } header("Content-type: image/jpeg");