Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ugeugeHigh
Last active February 10, 2019 01:47
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 ugeugeHigh/6d3f1551f247877eef490ea629850544 to your computer and use it in GitHub Desktop.
Save ugeugeHigh/6d3f1551f247877eef490ea629850544 to your computer and use it in GitHub Desktop.
<?php
$file = $_FILES['my_img'];
$ext = substr($file['name'], -4); //ファイル名の後ろ4文字を取得。つまり拡張子を取り出す
if($ext == '.gif' || $ext == '.jpg' || $ext == '.png' ) {
$filePath = 'tmp/' . $file['name']; //ファイルの移動先。
move_uploaded_file($file['tmp_name'], $filePath);//アップロード
print('<img src="'.$filePath.'" />');//アップロードした写真を表示する
}else {
print('error');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment