public static function updateAvatar($db, $type_name, $type_id) { $res = array(); $lokasi = public_path() . '/photos/'; $cover_photo_id = ''; // jika melakukan upload if (count($_FILES) > 0 && isset($_FILES)) { if (!empty($_FILES["cover_photo_id"]["tmp_name"])) { // Extension $ext = pathinfo($_FILES["cover_photo_id"]["name"], PATHINFO_EXTENSION); // cover photo tidak pernah di upload if (empty($db)) { $post = new Photo(); $post->user_id = Auth::user()->id; $post->type_name = $type_name; $post->type_id = $type_id; $post->status = 1; $post->save(); $cover_photo_id = $post->id; if (move_uploaded_file($_FILES["cover_photo_id"]["tmp_name"], $lokasi . $cover_photo_id . '.' . $ext)) { $img = Image::make($lokasi . $cover_photo_id . '.' . $ext); if ($ext != 'jpg') { $img->encode('jpg', 75); $img->save($lokasi . $cover_photo_id . '.jpg'); } $img->fit(200); $img->save($lokasi . 'thumb_' . $cover_photo_id . '.jpg'); // Menghapus file lama setelah kita meng-convert-nya ke jpg if ($ext != 'jpg') { if (file_exists($lokasi . $cover_photo_id . '.' . $ext)) { unlink($lokasi . $cover_photo_id . '.' . $ext); } } } } else { $post = new Photo(); $post->user_id = Auth::user()->id; $post->type_name = $type_name; $post->type_id = $type_id; $post->status = 1; $post->save(); $cover_photo_id = $post->id; if (move_uploaded_file($_FILES["cover_photo_id"]["tmp_name"], $lokasi . $cover_photo_id . '.' . $ext)) { $img = Image::make($lokasi . $cover_photo_id . '.' . $ext); if ($ext != 'jpg') { $img->encode('jpg', 75); $img->save($lokasi . $cover_photo_id . '.jpg'); } $img->fit(200); $img->save($lokasi . 'thumb_' . $cover_photo_id . '.jpg'); // Menghapus file lama setelah kita meng-convert-nya ke jpg if ($ext != 'jpg') { if (file_exists($lokasi . $cover_photo_id . '.' . $ext)) { unlink($lokasi . $cover_photo_id . '.' . $ext); } } } // Removing the old file Photo::remove($db); } } else { $cover_photo_id = $db; } $res = array('cover_photo_id' => $cover_photo_id); return $res; } }
<?php // $Id$ set_include_path(get_include_path() . ":../"); require_once "includes/session.php"; require_once "includes/utils.php"; require_once "includes/permissions.php"; require_once "includes/photo.php"; $session = Session::singletone(); if ($session->requireLogin()) { exit; } if (!Permissions::checkPerm('admin_panel')) { die("Permission denied."); } if (!Permissions::checkPerm('delete_photos')) { die("Permission denied."); } $ref = urldecode(Utils::pg("ref")); $pid = urldecode(Utils::pg("pid")); if (empty($pid)) { die; } $photo = new Photo($pid); $photo->remove(); header("Location: {$ref}"); ini_restore('include_path');
/** * undocumented function * * @return void * @author **/ public function deleteDo() { $id = Input::get('id'); $photo = Photo::remove($id); // Mengupdate semua fitur yang menggunakan foto menjadi 0 Events::where('default_photo_id', $id)->update(['default_photo_id' => 0]); Events::where('cover_photo_id', $id)->update(['cover_photo_id' => 0]); SocialAction::where('default_photo_id', $id)->update(['default_photo_id' => 0]); SocialAction::where('cover_photo_id', $id)->update(['cover_photo_id' => 0]); SocialTarget::where('default_photo_id', $id)->update(['default_photo_id' => 0]); SocialTarget::where('cover_photo_id', $id)->update(['cover_photo_id' => 0]); if ($photo) { $lokasi = public_path() . '/photos/'; if (unlink($lokasi . $id . '.jpg') && unlink($lokasi . 'thumb_' . $id . '.jpg')) { return Redirect::route('admin.photo')->withStatuses(['delete' => 'Hapus Sukses']); } return Redirect::route('admin.photo')->withErrors(['delete' => 'Delete File Gagal']); } return Redirect::route('admin.photo')->withErrors(['delete' => 'Delete File Gagal']); }