public static function uploadpic($file, $smallkey, $bigkey, $size, $const = array()) { $fd = Fun::uploadfile_post($file, $const); if ($fd["ec"] > 0) { $smallpic = "data/files/" . Fun::getuploadfilename(pathinfo($fd['fn'], PATHINFO_EXTENSION), 'small'); resizeimg($fd["fn"], $smallpic, $size, $size); Sqle::updateVal("users", array($smallkey => $smallpic, $bigkey => $fd["fn"]), array("id" => User::loginId())); } return $fd["ec"]; }
<?php /* * PHP GD * resize an image using GD library */ $ids = array("50m_lauf_02", "weitsprung_01", "staffellauf_02", "staffellauf_03", "weitsprung_01", "weitwurf_01"); $path = "../img/impressions/"; foreach ($ids as $id) { resizeimg(400, 600, $path, $id); } function resizeimg($height, $width, $path, $id) { $loc = $path . $id . ".jpg"; // Content type header('Content-Type: image/jpeg'); // Load $source = imagecreatefromjpeg($loc); list($oldwidth, $oldheight) = getimagesize($loc); $scaleH = $height / $oldheight; $scaleW = $width / $oldwidth; if ($scaleH > $scaleW) { $scale = $scaleH; } else { $scale = $scaleW; } $height = $height * $scale; $width = $width * $scale; $thumb = imagecreatetruecolor($width, $height); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $oldwidth, $oldheight);
return $_SERVER['PHP_SELF']; // if(array_key_exists("PATH_INFO", $_SERVER)) { // return substr($_SERVER["PATH_INFO"], 1); // } else // return ""; } //print_r($_SERVER); $_GET[""] = "mohit"; $_POST[""] = "mohit"; $_SESSION[""] = "mohit"; $_FILES[""] = "mohit"; $addinfo = array("ip" => $_SERVER['REMOTE_ADDR']); $pydata = array("get" => $_GET, "post" => $_POST, "session" => $_SESSION, "url" => curpathinfo(), "file" => $_FILES, "addinfo" => $addinfo); $cmd = "cd " . $root . ";" . "python " . $pyfile . " \"" . replall(tojson($pydata), array('\\' => '\\\\', "\t" => "\\t", "\n" => "\\n", '"' => "\\\"")) . "\" 2>&1"; //echo $cmd."<br>"; $pyoutp = shell_exec($cmd); $pyoutp1 = json_decode($pyoutp, true); if ($pyoutp1 == null) { echo str_replace("\n", "<br>", $pyoutp); } else { $_SESSION = $pyoutp1["_SESSION"]; if ($pyoutp1["_header"] != "") { header($pyoutp1["_header"]); } else { echo $pyoutp1["printout"]; } foreach ($pyoutp1["toresize"] as $name => $valp) { resizeimg($name, $valp[0], $valp[1], $valp[2]); } // print_r( $pyoutp1["toresize"] ); }
${$def_ava} = 1; } else { // Když není defaultní tak ho odstraníme unlink("avatar/" . $result4['avatar']); } // Jinak, jestli byl zadán nový obrázek } else { // Použijeme naši funkci upload_file() a uložíme nový avatar do proměnné $avatar $avatar = upload_file(); // Pokud je i po použití funkce proměnná $avatar prázdná, tak do ní uložíme defaultní hodnotu // Toto se může stát na lokálním serveru, třeba u mě se neukládájí soubory na localhost if ($avatar == '') { $avatar = 'no_avatar.jpg'; } else { // Uděláme z původního obrázku, obrázek o velikosti 90x90 $mini_av = resizeimg("avatar/{$avatar}", "avatar/mini-{$avatar}", 90, 90); // Odstraníme hned původní obrázek unlink("avatar/" . $avatar); $avatar = 'mini-' . $avatar; } /*** Odstraníme starý obrázek ***/ // Vybereme stávající obrázek uživatele $query5 = mysqli_query($dataconection, "SELECT `avatar` FROM `users` WHERE `login`='" . $login . "'"); $result5 = mysqli_fetch_assoc($query5); // Pokud je obrázek defaultní tak ho nechceme odstranít, protože je jeden pro všechny if ($result5['avatar'] == $def_ava) { $def_ava = 1; } else { // Když není defaultní tak ho odstraníme unlink("avatar/" . $result5['avatar']); }
function add_photo($photoname, $tag_select, $tag, $descr, $scope, $scope_orgnl, $group_box, $file, &$id_album, $alb_sel, $new_alb, $ignore, $cmt_rgt) { $error = ''; $user = $_SESSION['id_user']; if (empty($scope)) { $error .= 'Область видимости не задана<br>'; } $im_type = substr($file['type'], -(strlen($file['type']) - strpos($file['type'], "/") - 1)); if (!$file['tmp_name']) { $error .= 'Фото не выбрано<br>'; } elseif (substr($file['type'], 0, strpos($file['type'], "/")) != 'image') { $error .= "Файл не является изображением<br>"; } elseif (substr($file['type'], 0, strpos($file['type'], "/")) == 'image') { if (!($im_type == 'jpeg' or $im_type == 'pjpeg' or $im_type == 'gif' or $im_type == 'png' or $im_type == 'x-png')) { $error .= "Загрузка изображения данного типа не поддерживается<br>"; } } if (!$id_album) { if ($alb_sel == 0 and empty($new_alb)) { $error .= "Альбом не выбран<br>"; } elseif (!empty($new_alb) and $error == "") { $albscope[0] = 'all'; $this->add_album($new_alb, $albscope, '', $id_album); } elseif ($alb_sel != 0) { $id_album = $alb_sel; } } if ($error == "") { if (empty($photoname)) { $photoname = substr($file['name'], 0, strrpos($file['name'], ".")); } if ($im_type == 'jpeg' or $im_type == 'pjpeg') { $exif = exif_read_data($file['tmp_name'], 0, true); $ort = $exif['IFD0']['Orientation']; } if ($exif['IFD0']['DateTime'] != null) { $datetime = explode(" ", $exif['IFD0']['DateTime']); $date1 = explode(":", $datetime[0]); $time2 = explode(":", $datetime[1]); $date_ins = "'" . date("Y-m-d H:i:s", mktime($time2[0], $time2[1], $time2[2], $date1[1], $date1[2], $date1[0])) . "'"; } else { $date_ins = "NULL"; } //$ort = $exif['IFD0']['Orientation']; //$t = date("YmdHis",$exif['IFDO']['DateTime']); $ext = strrchr($file['name'], "."); $root_name = $user . date("YmdHis", time()); $size_photo = getimagesize($file['tmp_name']); if (!file_exists("../files/" . $_SESSION['id_user'])) { mkdir("../files/" . $_SESSION['id_user']); } if (!file_exists("../files/" . $_SESSION['id_user'] . "/" . $id_album)) { mkdir("../files/" . $_SESSION['id_user'] . "/" . $id_album); } $path = "../files/" . $_SESSION['id_user'] . "/" . $id_album . "/"; $photo = $path . $root_name . $ext; $degrees = 0; if (!$ignore) { switch ($ort) { case 8: $degrees = 90; break; case 6: $degrees = -90; break; case 3: $degrees = 180; break; } } /* switch ($ort) { case 8 : $degrees = 270; break; case 6 : $degrees = 90; break; case 3 : $degrees = 180; break; } */ if ($size_photo[1] <= 100 and $size_photo[0] <= 100) { if (copy($file['tmp_name'], $photo)) { $values = "'" . $root_name . $ext . "', '" . $root_name . $ext . "', '" . $root_name . $ext . "', '" . $root_name . $ext . "'"; } //chmod($photo, 0644); } elseif ($size_photo[1] <= 152 and $size_photo[0] <= 152) { $sml_photo = $path . "sml" . $root_name . $ext; resizeimg2($file['tmp_name'], $sml_photo, 100, 100, $degrees); //chmod($photo, 0644); //chmod($sml_photo, 0644); $values = "'sml" . $root_name . "{$ext}', '" . $root_name . "{$ext}', '" . $root_name . "{$ext}', '" . $root_name . $ext . "'"; copy($file['tmp_name'], $photo); } elseif ($size_photo[0] <= 622) { $mdm_photo = $path . "mdm" . $root_name . $ext; $sml_photo = $path . "sml" . $root_name . $ext; if ($size_photo[1] < $size_photo[0]) { resizeimg($file['tmp_name'], $mdm_photo, 175, 152, $degrees); } else { resizeimg($file['tmp_name'], $mdm_photo, 153, 175, $degrees); } resizeimg2($file['tmp_name'], $sml_photo, 100, 100, $degrees); $values = "'sml" . $root_name . $ext . "', 'mdm" . $root_name . $ext . "', '" . $root_name . $ext . "', '" . $root_name . $ext . "'"; copy($file['tmp_name'], $photo); } else { $maxi_photo = $path . "maxi" . $root_name . $ext; $mdm_photo = $path . "mdm" . $root_name . $ext; $sml_photo = $path . "sml" . $root_name . $ext; resizeimg2($file['tmp_name'], $sml_photo, 100, 100, $degrees); if ($size_photo[1] < $size_photo[0]) { resizeimg($file['tmp_name'], $mdm_photo, 175, 152, $degrees); } else { resizeimg($file['tmp_name'], $mdm_photo, 153, 175, $degrees); } // variable should be at least $size_photo[1] resizeimg($file['tmp_name'], $maxi_photo, 618, 618, $degrees); //stop copy($file['tmp_name'], $photo); $values = "'sml" . $root_name . $ext . "', 'mdm" . $root_name . $ext . "', 'maxi" . $root_name . $ext . "', '" . $root_name . $ext . "'"; } unlink($file['tmp_name']); /* if( !empty($month) and !empty($month) and !empty($month) ) { settype($month, 'integer'); settype($day, 'integer'); settype($year, 'integer'); $date_ins = "'".date("Y-m-d", mktime(0, 0, 0, $month, $day, $year))."'"; } else { $date_ins = "NULL"; } */ //$time_ins = "'$time'"; $field = $value = ""; if (isset($cmt_rgt)) { $field = ", `cmt_rgt`"; $value = ", '{$cmt_rgt}'"; } $this->q("INSERT INTO `photo` (`small`, `medium`, `maxi`, `original`, `pubdate`, `id_user`,\n\t\t\t\t\t\t\t\t\t\t `id_album`, `shootdate`, `descr`, `scope`, `scope_orgnl`, `name`, `ip`" . $field . ") \n\t\t\t\t\t VALUES (\n\t\t\t\t\t\t" . $values . ", NOW(), " . $_SESSION['id_user'] . ", " . $id_album . ", " . $date_ins . ", '" . addslashes(strip_tags($descr)) . "', '" . $scope[0] . "', '" . $scope_orgnl . "', '" . addslashes(strip_tags($photoname)) . "', INET_ATON('" . get_ip() . "')" . $value . ") "); $id_photo = mysql_insert_id(); // group manipulation $group_values = ''; if (isset($group_box)) { $group_values = "({$id_photo}, " . array_shift($group_box) . ")"; foreach ($group_box as $id_group) { $group_values .= ", ({$id_photo}, {$id_group})"; } $this->q("INSERT INTO `group_photo`(`id_photo`, `id_group`) VALUES " . $group_values); } //-- // tag manipulation if (!empty($tag)) { $tag_array = explode(", ", $tag); foreach ($tag_array as $tag_value) { $res = $this->q("SELECT `id_tag` FROM `tag` WHERE `name` LIKE '" . addslashes($tag_value) . "'"); $tagexist = mysql_num_rows($res); if ($tagexist) { //$this->q("UPDATE `tag` SET `name`='$tag_value', `rate`=NOW() WHERE `name` LIKE '$tag_value'"); $row = mysql_fetch_assoc($res); $id_tag = $row['id_tag']; } else { $this->q("INSERT INTO `tag`(`name`, `id_user`)\n\t\t\t\t\t\t\t\t VALUES('" . trim(addslashes(strip_tags($tag_value))) . "', {$user})"); $id_tag = mysql_insert_id(); } $this->q("INSERT INTO `tag_photo`(`id_tag`, `id_photo`, `rate`) VALUES({$id_tag}, {$id_photo}, NOW())"); } } //--- $res = $this->q("SELECT `small` FROM `photo` WHERE `id_album`=" . $id_album); $alb = mysql_fetch_assoc($this->q("SELECT `image` FROM `album` WHERE `id_album`=" . $id_album)); if (mysql_num_rows($res) == 1 and $alb['image'] == 'emptyalbum.gif') { $img = mysql_fetch_assoc($res); $this->q("UPDATE `album` SET `image`='" . $img['small'] . "' WHERE `id_album`=" . $id_album); } return 1; } else { return $error; } }
// Обработчик HTML-формы if(!empty($_POST)) { $error = $form->check(); if (empty($error)) { if ($firm->fields['showhide']->value) { $showhide = 'show'; }else{ $showhide = 'hide'; } $var = $form->fields['urlpict']->get_filename(); if ($var) { $picture = date('y_m_d_h_i_').$var; $picture_small ='S_'.$picture; resizeimg("../../media/images/".$picture,"../../media/images/".$picture_small,200,200); }else{ $picture= ""; $picture_small = ""; } $query = "INSERT INTO $_tbl_picture VALUES (NULL,'{$form->fields['name']->value}','{$form->fields['editor1']->value}','$picture','$picture_small',NOW(),'$showhide','{$form->fields['razdel']->value}')"; $q = mysql_query($query); if (!$q) { exit($query); } ?> <script> document.location.href = 'index.php'; </script> <?