목록에서 첨부파일 여러개 다운받기
본문
갤러리 게시판 스킨을 수정 중인데요,
첨부파일 1은 사진 / 2는 DWG / 3은 PDF
이런 식으로 딱 고정해서 각 형식에 맞게 파일을 등록하게 하고
목록에 사진 띄우고 첨부파일 2, 3을 다운받게 하고자 합니다.
(뷰 페이지는 사용 안 하는 방식)
단 첨부파일 2번, 3번은 필수 등록이 아니기 때문에 게시물마다 사용할 수도 있고 안 할 수도 있고요.
아무튼 이래저래 검색하고 짜집기해서
<?php if($list[$i]['file'][1]['file']){ ?><a href="<?=$list[$i]['file'][1]['href']?>&js=on">DWG</a><?php }?>
<?php if($list[$i]['file'][2]['file']){ ?><a href="<?=$list[$i]['file'][2]['href']?>&js=on">PDF</a><?php }?>
이렇게 해봤어요.
문제는... 2번만 첨부하거나 2, 3 모두 첨부하면 상관없는데
3번만 첨부할 경우에는 PDF 다운 링크가 안 나오네요 ㅠㅠ
첨부파일이 순서대로 등록되지 않아서일까요, 아니면 코드 문제일까요?
도움 부탁드립니다.
!-->
답변 2
2번을 건너띄고 3번만 업로드하시면 파일 업로드 되는 위치가
당연히 2번의 자리인 file[1]로 들어가게됩니다.
업로드를 할때에 강제로 file[0],file[1],file[2]
이와같이 강제로 그자리에 업로드되도록 바꾸셔야합니다.
이런식으로 강제로 나누어주세요
<tr>
<th scope="row">프로필 등록</th>
<td>
<input type="file" name="bf_file[]" title="파일첨부 1 : 용량 <?php echo $upload_max_filesize ?> 이하만 업로드 가능" class="frm_file frm_input">
<?php if ($is_file_content) { ?>
<input type="text" name="bf_content[]" value="<?php echo ($w == 'u') ? $file[0]['bf_content'] : ''; ?>" title="파일 설명을 입력해주세요." class="frm_file frm_input">
<?php } ?>
<?php if($w == 'u' && $file[0]['file']) { ?>
<input type="checkbox" id="bf_file_del0" name="bf_file_del[0]" value="1"> <label for="bf_file_del0"><?php echo $file[0]['source'].'('.$file[0]['size'].')'; ?> 파일 삭제</label>
<?php } ?>
</td>
</tr>
<tr>
<th scope="row">내용 등록</th>
<td>
<input type="file" name="bf_file[]" title="파일첨부 2 : 용량 <?php echo $upload_max_filesize ?> 이하만 업로드 가능" class="frm_file frm_input">
<?php if ($is_file_content) { ?>
<input type="text" name="bf_content[]" value="<?php echo ($w == 'u') ? $file[1]['bf_content'] : ''; ?>" title="파일 설명을 입력해주세요." class="frm_file frm_input">
<?php } ?>
<?php if($w == 'u' && $file[1]['file']) { ?>
<input type="checkbox" id="bf_file_del1" name="bf_file_del[1]" value="1"> <label for="bf_file_del1"><?php echo $file[1]['source'].'('.$file[1]['size'].')'; ?> 파일 삭제</label>
<?php } ?>
</td>
</tr>
굳이 첨부파일순서를 고정할 필요없이 업로드된 파일확장자을 출력하면 될 듯합니다.
2번째 파일의 확장자가 dwg면 DWG를 보여줄테고 pdf면 PDF로 보여줄테니 말이죠;;;
<?php if($list[$i]['file'][1]['file']){ ?><a href="<?=$list[$i]['file'][1]['href']?>&js=on"><?php echo strtoupper(end(explode('.', $list[$i]['file'][1]['file']))); ?></a><?php }?>
<?php if($list[$i]['file'][2]['file']){ ?><a href="<?=$list[$i]['file'][2]['href']?>&js=on"><?php echo strtoupper(end(explode('.', $list[$i]['file'][1]['file']))); ?></a><?php }?>