파일 업로드
업로드할 파일을 선택할 수 있는 컨트롤을 생성
문법
1 | <input type= "file" name= "서버쪽에서 파일을 식별하기 위한 이름" /> |
예제
example1.html (jsfiddle, github)
1 2 3 4 5 6 7 8 9 10 11 12 | <!DOCTYPE html> <html> <head> <meta http-equiv= "Content-Type" content= "text/html;charset=utf-8" > </head> <body> <form action= "example_receive.php" method= "POST" enctype= "multipart/form-data" > <input type= "file" name= "image" /> <input type= "submit" /> </form> </body> </html> |
example_receive.php (jsfiddle, github)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <!DOCTYPE html> <html> <head> <meta http-equiv= "Content-Type" content= "text/html;charset=utf-8" > </head> <body> <?php $uploaddir = '/var/www/codingeverybody_html_tutorial/upload_75/' ; $uploadfile = $uploaddir . basename ( $_FILES [ 'image' ][ 'name' ]); move_uploaded_file( $_FILES [ 'image' ][ 'tmp_name' ], $uploadfile ); ?> <img src= "<?=$_FILES['image']['name']?>" /> </body> </html> |