-
-
Save codeforfun-jp/6f3d31e227ccd752d371ac845c8cd7b6 to your computer and use it in GitHub Desktop.
Save Image File with PHP & MySQL - #8-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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