function createSessId() { return makeRandStr(200); }
} $moji = imagecreatefrompng("temp.png"); // 色のチェック if ($hcolor == "aka") { $maru = imagecreatefrompng("r12.png"); } elseif ($hcolor == "shu") { $maru = imagecreatefrompng("s12.png"); } elseif ($hcolor == "beni") { $maru = imagecreatefrompng("b12.png"); } // 完全なアルファチャネル情報を保存するフラグをonにする imagesavealpha($moji, true); imagesavealpha($maru, true); imagecopy($maru, $moji, 0, 0, 0, 0, 34, 34); // ファイル名の作成 $filename = makeRandStr(4); $destination = "hanko_" . $filename . ".png"; imagepng($maru, $destination); imagedestroy($maru); imagedestroy($moji); // ダウンロードの処理 header('Content-Type: application/force-download'); header('Content-Length: ' . filesize($destination)); header('Content-disposition: attachment; filename="' . $destination . '"'); readfile($destination); // ダウンロード後ファイルを削除する unlink($destination); unlink("temp.png"); /** * ランダム文字列生成 (英数字) * $length: 生成する文字数
<?php define("EXPORT_PATH", "/tmp/gyazo/"); define("URL_BASE", "https://bar.foo/"); /** * ランダム文字列生成 (英数字) * $length: 生成する文字数 */ function makeRandStr($length) { $str = array_merge(range('a', 'z'), range('0', '9'), range('A', 'Z')); $r_str = ""; for ($i = 0; $i < $length; $i++) { $r_str .= $str[rand(0, count($str))]; } return $r_str; } $hashFileName = makeRandStr(16) . '.png'; $url = URL_BASE . $hashFileName; $data = file_get_contents($_FILES['UploadFile']['tmp_name']); file_put_contents(EXPORT_PATH . $hashFileName, $data); echo $url;
} return $r_str; } //time関数用の設定 date_default_timezone_set('Asia/Tokyo'); // SELECT文でlessonsからidで指定して全カラム取得 // UPDATE文でlessonsのidが一致するもののstudent_idとstatusを変更 if (isset($_POST["lesson_id"])) { $sql = sprintf('SELECT * FROM lessons WHERE id=%d', $_POST["lesson_id"]); $lesson = mysqli_query($db, $sql) or die(mysqli_error($db)); $lesson = mysqli_fetch_assoc($lesson); } if (isset($_POST["confirm"])) { if ($_POST["confirm"] == "on") { //乱数生成関数の呼び出し $radomStr = makeRandStr(8); //レッスンテーブルのアップデート $sql = sprintf('UPDATE lessons SET student_id=%d, reserve_status_id=2, rand_str = "%s", modified=NOW() WHERE id=%d', $_SESSION["join"]["id"], $radomStr, $_POST["lesson_id"]); mysqli_query($db, $sql) or die(mysqli_error($db)); header('Location: thanks'); exit; } } ?> <div class="container"> <div class="row"> <h1>予約情報の確認</h1> </div>
{ $ch = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $chLength = strlen($ch); $random = ''; for ($i = 0; $i < $length; $i++) { $random .= $ch[rand(0, $chLength - 1)]; } return $random; } //gets post data $lname = $_POST['lname']; $fname = $_POST['fname']; $uname = $_POST['uname']; $passc = $_POST['pc']; //creates random string for a salt, hashes password with salt $newSalt = makeRandStr(); $pc = hash('sha256', $newSalt . $passc); //checks if username is already in database and errors if it is if (!($stmt = $mysqli->prepare('SELECT uname FROM player WHERE uname = (?)'))) { echo "<p>You did not enter a valid username or password.</p>"; } if (!$stmt->bind_param("s", $uname)) { echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error; } if (!$stmt->execute()) { echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error; } if ($stmt->num_rows !== 0) { echo "That user name is already taken."; } else { $stmt->close();
} } // 画像アップロード処理 if (!checkPostMaxSize()) { $errors[] = 'ファイルサイズは100KB以下にしてください'; } if (isset($_FILES['user_profile_photo'])) { for ($i = 0; $i < count($_FILES['user_profile_photo']['name']); $i++) { // アップロードファイルチェック list($result, $ext, $error_msg) = checkFile($i); $errors = array_merge($errors, $error_msg); if ($result) { $name = $_FILES['user_profile_photo']['name'][$i]; $tmp_name = $_FILES['user_profile_photo']['tmp_name'][$i]; // 画像保存先ファイルパス $move_to = $dir_tmp . makeRandStr() . $ext; // アップロードした一時ファイルを指定した場所へ移動します if (!move_uploaded_file($tmp_name, $move_to)) { $errors[] = '画像のアップロードに失敗しました'; if ($i == 0) { $_SESSION['user_profile_photo'] = ''; } else { $_SESSION['user_profile_background'] = ''; } } else { if ($i == 0) { $_SESSION['user_profile_photo'] = $move_to; } else { $_SESSION['user_profile_background'] = $move_to; } }
$errors[] = '文字数は200文字以内にしてください'; } } if (isset($_FILES['edit_user_profile_photo'])) { // todo: 画像アップロード入力チェック if (!checkPostMaxSize()) { $errors[] = 'ファイルサイズは100KB以下にしてください'; } // アップロードファイルチェック list($result, $ext, $error_msg) = checkUpdateFile(); $errors = array_merge($errors, $error_msg); if ($result) { $name = $_FILES['edit_user_profile_photo']['name']; $tmp_name = $_FILES['edit_user_profile_photo']['tmp_name']; // 画像保存先ファイルパス $move_to = $dir_src . makeRandStr() . $ext; // アップロードした一時ファイルを指定した場所へ移動します if (!move_uploaded_file($tmp_name, $move_to)) { $errors[] = '画像のアップロードに失敗しました'; $edit_user_profile_photo = ''; } else { $edit_user_profile_photo = $move_to; } } if (count($errors) === 0) { if (!$profile->profileEdit($db, $login_id, $edit_user_name, $edit_user_profile, $edit_user_profile_photo)) { $errors[] = '更新に失敗しました'; } else { header('HTTP/1.1 303 See Other'); header('Location: http://localhost/utwitter/htdocs/profile_controller.php?action_id=profile&user_profile_id=' . $login_id); exit;