0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【備忘録】写真のアップロード方法

Posted at

最近、エラーが埋まってる埋まってないで考えると楽になるのかなと感じる

HTMLにて

これをすることにより、ファイルから選ぶことができる

join.php
input type="file"

PHPにて

理解はしていない… 上のPHPで名前(?)を決める

join.php
	$fileName = $_FILES['image']['name'];
	if(!empty($fileName)) {
$ext = substr($fileName, -3);
//写真のタイプを選定し、エラーを作る//
if($ext != 'jpg' && $ext !='gif') {
	$error['image'] = 'type';
} 
	}

PHPにて

上の2行でフォルダ内にアップロードできるようになる

join.php
	
	if(empty($error) ) {
//写真のアップロードの決まり文句らしい//
		$image = date('YmdHis') . $_FILES['image']['name'];
		move_uploaded_file($_FILES['image']['tmp_name'], '../member_picture/' . $image);

//ちょっとしたまとめ//
		$_SESSION['join'] = $_POST;
		$_SESSION['join']['image'] = $image;
		header('Location: check.php');
		exit();
	}

次の画面にて

これで表示OK

check.php

		<?php if($_SESSION['join']['image'] !==''):?>
		<img src="../member_picture/<?php print (htmlspecialchars($_SESSION['join']['image'],ENT_QUOTES));?>" >
			<?php endif ;?>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?