Пример #1
0
 function uploadAvatar($input_name, $max_file_size)
 {
     $overwrite = 1;
     $dir = 'upload/avatars/';
     $file_types = array(1 => 'jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPEG', 'GIF', 'PNG');
     $file_mimes = array(1 => 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
     $file_name = $_SESSION['login'] . '_user';
     if (isset($_POST['send_avatar'])) {
         if (!$_FILES[$input_name]['name']) {
             $this->msg('Nie wybrano pliku do załadowania!', 1);
         } else {
             if (filesize($_FILES[$input_name]['tmp_name']) <= $max_file_size * 1024) {
                 $file_ex = pathinfo($_FILES[$input_name]['name']);
                 $image_info = @getimagesize($_FILES[$input_name]['tmp_name']);
                 if (array_search($file_ex['extension'], $file_types) && array_search($image_info['mime'], $file_mimes)) {
                     if ($overwrite == 0 && file_exists($dir . $file_name . "." . $file_ex['extension'])) {
                         $this->msg('Taki plik już istnieje.', 1);
                     }
                     if (!move_uploaded_file($_FILES[$input_name]['tmp_name'], $dir . $file_name . "." . $file_ex['extension'])) {
                         $this->msg('Wgrywanie pliku nie powiodło się.', 1);
                     } else {
                         $upload_dir = $dir . $file_name . "." . $file_ex['extension'];
                         mysql_query("UPDATE `{$this->table}` SET `avatar`='{$upload_dir}' WHERE `user`='" . $_SESSION['login'] . "'");
                         //Zmina rozmiaru avatara
                         list($width, $height, $type, $attr) = getimagesize($upload_dir);
                         if ($width > 120 || $height > 120) {
                             require_once 'admin/lib/imageworkshop.lib.php';
                             $createFolders = false;
                             $backgroundColor = null;
                             $imageQuality = 95;
                             $imageLayer = new ImageWorkshop(array("imageFromPath" => $upload_dir));
                             $imageLayer->resizeInPixel(120, 120, true);
                             $imageLayer->save($dir, $file_name . "." . $file_ex['extension'], $createFolders, $backgroundColor, $imageQuality);
                         }
                         $this->msg('Avatar został pomyślnie załadowany.', 3);
                     }
                 } else {
                     $this->msg('Niedozwolone rozszerzenie lub typ pliku!', 1);
                 }
             } else {
                 $this->msg('Wybrany plik jest za wielki! Dozwolony rozmiar to ' . $max_file_size . ' kB.', 1);
             }
         }
     }
 }
Пример #2
0
 function uploadImage($max_width, $max_file_size, $owner, $watermark)
 {
     $overwrite = 0;
     $dir = 'upload/';
     $file_types = array(1 => 'jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPEG', 'GIF', 'PNG');
     $file_mimes = array(1 => 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png');
     $file_name = date('YmdHis') . 'uid' . $owner;
     if (isset($_POST['send_img'])) {
         if (empty($_POST['title']) || !$_FILES['image']['name']) {
             $this->msg('Uzupełnij wszystkie pola!', 1);
         } else {
             if ($_SESSION['img_number'] != strtolower($_POST['question'])) {
                 $this->msg('Kod weryfikacyjny nie jest poprawny!', 1);
             } else {
                 $title = mysql_real_escape_string(htmlspecialchars($_POST['title']));
                 if (!empty($_POST['source'])) {
                     $source = mysql_real_escape_string(htmlspecialchars($_POST['source']));
                 } else {
                     $source = '-----';
                 }
                 $cat = mysql_real_escape_string(htmlspecialchars($_POST['cat']));
                 $date = date('Y-m-d H:i:s');
                 $is_waiting = 1;
                 $type = 'img';
                 if (empty($_SESSION['login'])) {
                     $owner = 0;
                 }
                 if (filesize($_FILES['image']['tmp_name']) <= $max_file_size * 1024) {
                     $file_ex = pathinfo($_FILES['image']['name']);
                     $image_info = @getimagesize($_FILES['image']['tmp_name']);
                     if (array_search($file_ex['extension'], $file_types) && array_search($image_info['mime'], $file_mimes)) {
                         if ($overwrite == 0 && file_exists($dir . $file_name . "." . $file_ex['extension'])) {
                             $this->msg('Taki plik już istnieje.', 1);
                         }
                         if (!move_uploaded_file($_FILES['image']['tmp_name'], $dir . $file_name . "." . $file_ex['extension'])) {
                             $this->msg('Wgrywanie pliku nie powiodło się.', 1);
                         } else {
                             $upload_dir = $dir . $file_name . "." . $file_ex['extension'];
                             $file_src = $file_name . "." . $file_ex['extension'];
                             mysql_query("INSERT INTO `tentego_img` (`title`,`src`,`type`,`owner`,`cat`,`date`,`source`,`is_waiting`)\n\t\t\t\t\t\t\t\t\t\t\t\tVALUES ('{$title}','{$file_src}','{$type}','{$owner}','{$cat}','{$date}','{$source}','{$is_waiting}')");
                             //Zmina rozmiaru obrazka
                             list($width, $height, $type, $attr) = getimagesize($upload_dir);
                             if ($width > $max_width) {
                                 require_once 'admin/lib/imageworkshop.lib.php';
                                 $imageLayer = new ImageWorkshop(array("imageFromPath" => $upload_dir));
                                 $imageLayer->resizeInPixel($max_width, null, true);
                                 $createFolders = false;
                                 $backgroundColor = null;
                                 $imageQuality = 95;
                                 $imageLayer->save($dir, $file_name . "." . $file_ex['extension'], $createFolders, $backgroundColor, $imageQuality);
                             }
                             if ($watermark) {
                                 $this->watermark($upload_dir, $watermark, $dir);
                             }
                             $this->msg('Obiekt został pomyślnie załadowany.', 3);
                         }
                     } else {
                         $this->msg('Niedozwolone rozszerzenie lub typ pliku!', 1);
                     }
                 } else {
                     $this->msg('Wybrany plik jest za wielki! Dozwolony rozmiar to ' . $max_file_size . ' kB.', 1);
                 }
             }
         }
     }
 }