Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Last active August 24, 2022 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/6f3d31e227ccd752d371ac845c8cd7b6 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/6f3d31e227ccd752d371ac845c8cd7b6 to your computer and use it in GitHub Desktop.
Save Image File with PHP & MySQL - #8-1
<?php
/* 省略 */
if (!empty($_FILES['image']['name'])) {
$name = $_FILES['image']['name'];
$type = $_FILES['image']['type'];
$content = file_get_contents($_FILES['image']['tmp_name']);
$size = $_FILES['image']['size'];
// 画像のサイズ・形式チェック
$maxFileSize = 1048576;
$validFileTypes = ['image/png', 'image/jpeg'];
if ($size > $maxFileSize || !in_array($type, $validFileTypes)) {
$err_msg = '* jpg, jpeg, png 形式で 1 MB までの画像を選択してください。';
}
if ($err_msg == '') {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment