코딩을 갓배운 직장인입니다.
php에서 이미지를 서버 디렉토리 또는 db에 넣고싶습니다.
코드확인해주세요~
<?php echo $_SERVER['DOCUMENT_ROOT'].'/'.G5_IMG_URL.'/'; ?>
이런 코드를 이용해서 하는거 같긴 한데 전혀 모르겠습니다.
몇시간째 헤매고있습니다. 구해주세요~
업로드 코드
Copy
<form name='gp' method='post' action='golf_place_action.php' enctype="multipart/form-data"> <input type='hidden' id='gidx' name='gidx'> <input type='hidden' id='idx' name='idx'> <table> <tr> <th>골프장명</th> <td><span id='place_name'>골프장명 선택</span></td> </tr> <tr> <th>카트비</th> <td><input type='text' name='cart_price' id='cart_price' value='' class='frm_input' ></td> </tr> <tr> <th>날짜</th> <td><input type='text' name='place_date' class='frm_input' id='place_date'></td> </tr> <tr> <th>시간</th> <!--<textarea style='height:100px'></textarea>--> <td> <select name='place_time1' id='place_time1'> <option value='오전'>오전</option> <option value='오후'>오후</option> </select> <select name='place_time2' id='place_time2'> <option value=''>시</option> </select> : <select name='place_time3' id='place_time3'> <option value=''>분</option> </select> </td> </tr> <tr> <th>코스명</th> <td><input type='text' id='place_name' name='place_name' size='15' class='frm_input'></td> </tr> <tr> <th>배경 이미지</th> <td><input type="file" id='place_file' name='place_file' class='frm_input'></td> </tr> </table> <div class="btn_confirm01 btn_confirm" style='margin-top:10px'> <input type='submit' value='일정등록' id='btn_submits' class='btn_submit'> </div> </form>
액션 코드
Copy
<? include_once "_common.php"; if($_GET['idx'] && $_GET['mode'] == 'del') { sql_query("DELETE FROM glofPlaceSchedule WHERE idx = '".$_GET['idx']."'"); echo" <script> alert('삭제완료'); parent.location.href='golf_place.php'; </script> "; } else { sql_query("UPDATE g5_write_golf SET wr_1 = '".$_POST['cart_price']."' where wr_id = '".$_POST['gidx']."'"); if($_POST['idx']) { sql_query("UPDATE glofPlaceSchedule SET place_date = '".$_POST['place_date']."', place_time = '".trim($_POST['place_time'])."', place_name = '".trim($_POST['place_name'])."', place_file = '".trim($_POST['place_file'])."' WHERE idx = '".$_POST['idx']."' "); alert("수정완료","golf_place.php"); } else { //$tmp = explode("\n",$_POST['place_time']); // foreach($tmp AS $time) // { $time = "[".$_POST['place_time1']."]".$_POST['place_time2'].":".$_POST['place_time3']; sql_query("INSERT INTO glofPlaceSchedule SET gidx = '".$_POST['gidx']."', place_date = '".$_POST['place_date']."', place_file = '".$_POST['place_file']."', place_time = '".trim($time)."', place_name = '".trim($_POST['place_name'])."' "); //} alert("등록완료","golf_place.php"); } }?>
답변 1개 / 댓글 1개
채택된 답변
+20 포인트
9년 전
파일명은 $_FILES['place_file']['name'] 이런형태로 받아집니다.
위에 보여주신 부분은 단순하게 text만 디비에 저장하여 처리하는 부분입니다.
파일이 업로드되면 실제 서버에 물리적으로 파일이 업로드( 이동) 되는 코드가 필요합니다.
디렉토리생성, 파일 이동, 등등...
mkdir , move_uploaded_file... 함수 이용법을 찾아보세요..
답변에 대한 댓글 1개
답변을 작성하려면 로그인이 필요합니다.