Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Gallery {
- public function upload_pictures($images, $project_id_, $author_) {
- global $db, $msg;
- if(!empty($images['name'])) {
- //$images = $_FILES['images'];
- $uploaded = array();
- $failed = array();
- $allowed = array('jpg', 'jpeg', 'gif', 'png');
- //var_dump($images);
- foreach($images['name'] as $position => $image_name) {
- $image_tmp = $images['tmp_name'] [$position];
- $image_name = $images['name'] [$position];
- $image_size = $images['size'] [$position];
- $image_error = $images['error'] [$position];
- $image_ext = explode('.', $image_name);
- $image_ext = strtolower(end($image_ext));
- if(in_array($image_ext, $allowed)) {
- if($image_error === 0) {
- if($image_size <=30000000) {
- $image_name_new = uniqid().'_'.$image_name;
- $image_destination = APP_ROOT. '//uploads//' .$image_name_new;
- if(move_uploaded_file($image_tmp, $image_destination)) {
- $uploaded[$position] = $image_name_new;
- $this->insert_picture_db($project_id_, $image_name_new, $author_);
- } else {$failed[$position] = '['.$image_name.']';}
- } else {$failed[$position] = '['.$image_name.'] fails ir par lielu.';}
- } else {$failed[$position] = '['.$image_name.']'. ' bildes formāts nav atļauts.'; }
- }
- if(!empty($uploaded)) {
- foreach($uploaded as $key => $val) {
- echo $val;
- }
- }
- if(!empty($failed)) {
- //print_r($failed);
- }
- }
- }
- }
- public function insert_picture_db($project_id, $picture, $author) {
- global $db;
- $sql_pict = $db->prepare('INSERT INTO PICTURES (`project_id`, `picture`, `author`) VALUES (:project_id, :picture, :author)');
- $sql_pict2 = $sql_pict->execute([
- 'project_id' => $project_id,
- 'picture' => $picture,
- 'author' => $author,
- ]);
- var_dump($sql_pict);
- }
- public function show_edit_images($project_id_img) {
- global $db;
- $sh_ed_img1 = $db->prepare('SELECT `picture`, `id` FROM `pictures` WHERE `project_id` = :project_id_img');
- $sh_ed_img1->execute([
- 'project_id_img'=>$project_id_img,
- ]);
- $sh_ed_img2 = $sh_ed_img1->fetchAll();
- if($sh_ed_img2){
- echo '<div class="container padding-zero" style="padding-bottom: 10px; margin-left: -6px;">
- <div class="col-xs-12 padding-zero">';
- foreach ($sh_ed_img2 as $picture) {
- //var_dump($picture['picture']);
- echo '<div class="col-xs-3" style="height: 140px; width: 140px; background: url(\''. BASE_URL. '//uploads//' . $picture['picture'].'\'); background-size:cover; margin: 5px;"><a href="edit_project.php?id='.$project_id_img.'&del_img='.$picture['id'].'"><img src="img/icons/delete.png" style="top: 4px;left: 100px;position: relative;height: 20px;width: 20px;"></a></div>';
- }
- echo '
- </div>
- </div>';
- }
- }
- public function delete_image($del_img_id) {
- global $db, $user_id_session;
- $author_of_del = Misc::get_field_with_where('author', 'pictures', 'id', $del_img_id);
- //var_dump($img_name_of_del);
- $img_name_of_del = Misc::get_field_with_where('picture', 'pictures', 'id', $del_img_id);
- var_dump($user_id_session);
- if (($user_id_session === $author_of_del) || ($user_id_session === User::is_online_admin())) {
- $del_img_sql = $db->prepare('DELETE FROM `pictures` WHERE `id` = :del_img_id');
- $del_img_sql->execute([
- 'del_img_id'=>$del_img_id,
- ]);
- $del_file = APP_ROOT. '//uploads//' . $img_name_of_del;
- unlink($del_file);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement