[질문]파일 업로드시 디비 입력 오류에 대한 질문입니다.
파일업로드와 파일 구분 저장은 정상적으로 잘 됩니다.
그런데 지정해준 첨부파일이 아닐 경우에는 디비에 남지 않아야 하는데 남네요.
어디가 잘못 되었는지 조언 바랍니다.
나름데로 여기저기 알아보는데 통 알수가 없네요...
소스는 아래와 같습니다.
///////////////////////////////////////////////////////////////////////
<?
include "config.php";
if(!$userfile_name) {
$filepath = "첨부파일이 없습니다.";
$query = "insert into $board values ('','$name','$pass','$filepath','$userfile_name','$userfile_size',now())";
$result = mysql_query($query,$db);
echo ("
<script>
window.alert('정상적으로 파일 없이 잘 처리되었습니다.');
location.href='up.php';
</script>
");
}
else {
$save_path = "upload/";
$zip = "zip/";
$gif = "gif/";
$ext = explode(".",$userfile_name); /// post방식으로넘겨받은 파일명에서 파일명과 확장자를 분리
$file_ext = $ext[1];
$file_name = $ext[0];
if ($file_ext == "zip" || $file_ext == "gif") {
switch ($file_ext) {
case zip:
$find_path = $save_path.$zip;
break;
case gif:
$find_path = $save_path.$gif;
break;
}
}
else
{
echo ("
<script>
window.alert('[!] 사용할 수 없는 파일 형식입니다');
history.go(-1);
</script>
");
}
if ($userfile_size > 10000000000) {
echo ("
<script>
alert('파일 용량이 초과했습니다.')
history.go(-1)
</script>
");
exit; }
else {
if ($userfile_size > 0) {
exec("mv \"$userfile\" \"$find_path.$wdate/$userfile_name\"");
chmod("$find_path.$wdate/$userfile_name", 0644);
}
}
$filepath = $find_path.$userfile_name;
if (!$id) {
$query = "insert into $board values ('','$name','$pass','$filepath','$userfile_name','$userfile_size',now())";
$result = mysql_query($query,$db);
echo ("
<script>
window.alert('파일 첨부 정상 처리 되었습니다.');
location.href='up_list.php';
</script>
");
}
else {
echo ("
<script>
window.alert('[!]저장에 실패 했습니다.');
history.go(-1);
</script>
");
}
}
?>/////////////////////////////////////////////////////////////////////////////
해당 디비 내용입니다.
mysql> select * from test_board;
+----+--------+------+-----------------------+--------------+----------+---------------------+
| id | name | pass | filepath | filename | filesize | wdate |
+----+--------+------+-----------------------+--------------+----------+---------------------+
| 3 | dfs | dsf | upload/gif/shadow.gif | shadow.gif | 5476 | 2005-01-27 18:55:48 |
| 2 | xx | xcxc | upload/gif/over.gif | over.gif | 4473 | 2005-01-27 18:54:43 |
| 4 | hds | dfh | ÷ºÎÆÄÀÏÀÌ ¾ø½À´Ï´Ù. | | 0 | 2005-01-27 18:57:41 |
| 5 | gfhgfj | ghdj | ÁÂÃø¸Þ´º.txt | ÁÂÃø¸Þ´º.txt | 6637 | 2005-01-27 18:57:57 |
| 6 | 23 | g66q | ¸ÞÀÎ.txt | ¸ÞÀÎ.txt | 4573 | 2005-01-27 18:59:30 |
| 7 | dsa | dga | °øÁö.txt | °øÁö.txt | 2887 | 2005-01-27 19:04:53 |
+----+--------+------+-----------------------+--------------+----------+---------------------+
ID = 2 ~ 3 번은 지정 첨부파일이고요, 나머지는 지정 첨부파일이 아닙니다.


댓글 달기