php 완전 초보가 질문 드립니다..(업로드 파일명 정렬 문제)

· 12년 전 · 1821
130923_upload2.jpg
첨부된 그림처럼 최근에 업로드한 파일을 1페이지 상단에 보여주고 싶은데, 랜덤으로 보여지는 문제점이 있습니다.

제가 php 완전 초보라 도움을 요청해 봅니다...

(참고로 제로보드4 입니다..!!)

<<소스파일 참고>>
<html>
<head>

<meta http-equiv=ImageToolbar content=no>
<script>



function resizeWin(maxX,maxY,speed,delay,win){
this.obj = "resizeWin" + (resizeWin.count++);
eval(this.obj + "=this");
if (!win) this.win = self; else this.win = eval(win);
if (!maxX) this.maxX = 400; else this.maxX = maxX;
if (!maxY) this.maxY = 300; else this.maxY = maxY;
if (!speed) this.speed = 1/5; else this.speed = 1/speed;
if (!delay) this.delay = 0; else this.delay = delay;
this.doResize = (document.all || document.getElementById);
this.stayCentered = false;

this.initWin = function(){
if (this.doResize){
this.resizeMe();
}
else {
this.win.resizeTo(this.maxX + 10, this.maxY - 20);
}
}

this.resizeMe = function(){
this.win.focus();
this.updateMe();
}

this.resizeTo = function(x,y){
this.maxX = x;
this.maxY = y;
this.resizeMe();
}

this.stayCentered = function(){
this.stayCentered = true;
}

this.updateMe = function(){
this.resizing = true;
var x = Math.ceil((this.maxX - this.getX()) * this.speed);
var y = Math.ceil((this.maxY - this.getY()) * this.speed);
if (x == 0 && this.getX() != this.maxX) {
if (this.getX() > this.maxX) x = -1;
else x = 1;
}
if (y == 0 && this.getY() != this.maxY){
if (this.getY() > this.maxY) y = -1;
else y = 1;
}
if (x == 0 && y == 0) {
this.resizing = false;
}
else {
this.win.top.resizeBy(parseInt(x),parseInt(y));
if (this.stayCentered == true) this.win.moveTo((screen.width - this.getX()) / 2,(screen.height - this.getY()) / 2);
setTimeout(this.obj + '.updateMe()',this.delay)
}
}

this.write = function(text){
if (document.all && this.win.document.all["coords"]) this.win.document.all["coords"].innerHTML = text;
else if (document.getElementById && this.win.document.getElementById("coords")) this.win.document.getElementById("coords").innerHTML = text;
}

this.getX = function(){
if (document.all) return (this.win.top.document.body.clientWidth + 10)
else if (document.getElementById)
return this.win.top.outerWidth;
else return this.win.top.outerWidth - 12;
}

this.getY = function(){
if (document.all) return (this.win.top.document.body.clientHeight + 29)
else if (document.getElementById)
return this.win.top.outerHeight;
else return this.win.top.outerHeight - 31;
}

this.onResize = function(){
if (this.doResize){
if (!this.resizing) this.resizeMe();
}
}

return this;
}
resizeWin.count = 0;



</script>
<script>
booyah = new resizeWin(400,520);
booyah.stayCentered();

</script>

</head>
<div id="Layer1" style="position:absolute; left:0px; top:0px; width:319px; height:59px; z-index:1"><img src="miniwini.visualEditor/top_logo.gif" width="394" height="56" border="0" usemap="#Map">
<map name="Map">
<area shape="rect" coords="293,34,383,48" href="http://alik.bo.to" target="_blank" onfocus=this.blur(); title="(알릭님)엄청 도움주신분">
</map>
</div>
<?


if(!file_exists("icon/member_image_box"))@mkdir("icon/member_image_box", 0777);

if ($member[no]) {
@mkdir("./icon/member_image_box/"."$member[no]", 0777);

$upload_dir = "icon/member_image_box/$member[no]/";
} else { echo "로그인하세요"; exit(); }

$size_bytes = 2097152; //최대허용 파일크기 bytes (원하는데로 바꾸세요.. 최고 5메가, 현재 1메가)
//51200 bytes = 50KB, 2097152 bytes = 2MB

$extlimit = "yes"; //업로드가 허용되는 파일 확장자목록을 적용하시겠습니까? (yes/no)
$limitedext = array(".gif",".jpg",".png",".jpeg"); //업로드가 허용되는 파일 확장자 목록, 기타 예제: //array(".gif",".jpg",".jpeg",".png",".txt",".nfo",".doc",".rtf",".htm",".dmg",".zip",".rar",".gz",".exe");


if (!is_dir("$upload_dir")) {
die ("에러: <b>($upload_dir)</b> 폴더가 존재하지 않습니다");
}

if (!is_writeable("$upload_dir")){
die ("에러: <b>($upload_dir)</b> 의 폴더 권한설정을 777로 변경해주세요");
}

function file_delete($rm_file)
{
chmod($rm_file, 0777);
if(unlink($rm_file))
{
return true;
}else{
return false;
}
}

if ($delete) {


$rm_file_add = $_zb_path.$upload_dir.$delete;

if (substr ($index_url, -1) == "/") {
$return_add = $index_url."mw_upload.php";
} else {$return_add = $index_url."/mw_upload.php";
}

$result = file_delete($rm_file_add);
if ($result == true) {
// echo "<br><br><center>파일이 삭제되었습니다.<br><br><a href=\"$return_add\">확인</a>";
echo "<script> top.location.href = '$return_add' </script>";
// exit();
} else {
echo "<br><br><center>파일삭제중에 에러가 발생했습니다.<br><br><a href=\"$return_add\">확인</a>";
exit();
}
}

function in_array_cin($strItem, $arItems)
{
$bFound = FALSE;
foreach ($arItems as $strValue) {
if (strtoupper($strItem) == strtoupper($strValue)) {
$bFound = TRUE;
}
}
return $bFound;
}

function pageLink($totalPage, $nowPage, $limit, $URL)
{
$pageLink = "";
if ($totalPage <= $limit) {
for($i = 1; $i <= $totalPage; $i++) {
if ($i == $nowPage) $pageLink .= "|<span class='ol3-thisPage'> $i </span>";
else $pageLink .= "|<a href='" . $URL . "page=$i' class='ol3-page'> $i </a>";
}
$pageLink .= "|";
}

if ($totalPage > $limit) {
$inPage = ceil($nowPage / $limit);
if ($inPage == 1) $start = 1;
else {
$start = ($inPage - 1) * $limit + 1;
if ($inPage >= 2) $pageLink .= "|<a href='" . $URL . "page=1' class='ol3-page'> 1 </a>|..";
if ($inPage > 1) {
$prev = ($inPage - 1) * $limit;
$pageLink .= "|<a href='" . $URL . "page=$prev' class='ol3-page'> Prev </a>";
}
}
$end = $start + $limit - 1;
if ($end >= $totalPage) $end = $totalPage;
for($j = $start; $j <= $end; $j++) {
if ($j == $nowPage) $pageLink .= "|<span class='ol3-thisPage'> $j </span>";
else $pageLink .= "|<a href='" . $URL . "page=$j' class='ol3-page'> $j </a>";
}
if ($end != $totalPage) {
$next = $inPage * $limit + 1;
$pageLink .= "|<a href='" . $URL . "page=$next' class='ol3-page'> Next </a>|";
}
$inLastPage = ceil($totalPage / $limit);
if ($inPage < $inLastPage) $pageLink .= "..|<a href='" . $URL . "page=$totalPage' class='ol3-page'> $totalPage </a>|";
else $pageLink .= "|";
}
return "<span class=ol3-normal>" . $pageLink . "</span>\n";
}

if($uploadform)
{

if (!is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{
// echo "<br><br><br><center>에러: 업로드할 파일을 선택해주세요!. <br><br><a href=\"$_SERVER[PHP_SELF]\">확인</a>";
echo "<script> top.location.href = '$_SERVER[PHP_SELF]' </script>";
exit(); //exit the script and don't do anything else.
}


$size = $_FILES['filetoupload']['size'];

if ($size > $size_bytes)
{
$kb = $size_bytes / 1024;
echo "<br><br><br><center>파일사이즈가 너무 큽니다. <b>$kb</b> KB. 이하만 허용됩니다.<br><br><a href=\"$_SERVER[PHP_SELF]\">확인</a>";
exit();
}


$ext = strrchr($_FILES['filetoupload'][name],'.');
if (($extlimit == "yes") && (in_array_cin($ext,$limitedext) == false)) {
// echo("<br><br><br><center>업로드가 금지된 파일 확장자입니다.<br><br><a href=\"$_SERVER[PHP_SELF]\">확인</a>");
echo "<script> top.location.href = '$_SERVER[PHP_SELF]' </script>";
exit();
}


$filename = $_FILES['filetoupload']['name'];

if (substr ($index_url, -1) == "/") {
$file_add = $index_url.$upload_dir.$filename;
} else {
$file_add = $index_url."/".$upload_dir.$filename;
}

if(file_exists($upload_dir.$filename)){
echo "<br><br><br><center><font size=2><font color=red>같은 이름의 파일이 존재합니다,</font><br><br> <b>$filename </b><br><br><a href=\"$_SERVER[PHP_SELF]\">확인</a></font>";
exit();
}



if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {


// echo "<br><br><center>파일이름: ($filename) 업로드 되었습니다 <br><br><a href=\"$_SERVER[PHP_SELF]\">확인</a>";
echo "<script> top.location.href = '$_SERVER[PHP_SELF]' </script>";
exit();

}

else
{

echo "<br><br><br><center>알수없는 에러가 발생했습니다 - 다시 시도하세요 -. <br><br><a href=\"$_SERVER[PHP_SELF]\">확인</a>";
exit();
}



}

else
{

?>


<title>이미지 자료실</title>
<style>
td{font-family:돋움;font-size:12px;}
A:link { color:#000066; text-decoration:none; }
A:visited { color:#000066; text-decoration:none; }
A:hover { color:#D42340; text-decoration:none; }
</style>

<body topmargin="0" leftmargin="0" bgcolor="#EBEAE7" onload="booyah.initWin()" onresize="booyah.onResize()" onkeyup= javascript:keycontrol(); ondragstart='return false' onselectstart='return false'>
<table border=0 width=380 align=center>

<tr><td align=left><table><tr><td height="55"></td></tr></table>


<SPAN style="FILTER: dropshadow(color=#dedede, offx=1, offy=1, positive=1); WIDTH: auto; HEIGHT: 6px"><FONT color=#000000>- 허용된 확장자 =&nbsp;</FONT></SPAN>

<?

for($i=0;$i<count($limitedext);$i++)
{
if (($i<>count($limitedext)-1))$commas=", ";else $commas="";
list($key,$value)=each($limitedext);
echo $value.$commas;
}
?>
</b>

<br>
<SPAN style="FILTER: dropshadow(color=#dddddd, offx=1, offy=1, positive=1); WIDTH: auto; HEIGHT: 6px"><FONT color=#000000>- 허용된 최대 파일크기 = </FONT></SPAN> <b>&nbsp;<?echo $size_bytes / 1024; ?> KB </b>
<br>




<script>
function fnChgImg() {

document.board.myImg.src = document.board.filetoupload.value;
document.board.myImg.style.visibility = 'visible';

}
</script>

<form name="board" method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF ?>">

<div id="Layer1" style="position:absolute; left:30px; top:90px; width:80px; height:80px; z-index:39">
<IMG id=myImg alt='미리보기 이미지..~!!' Style='VISIBILITY: hidden; width=80; height=80; POSITION: relative; TOP: 2px'>
</div>

<div id="Layer1" style="position:absolute; left:30px; top:92px; width:80px; height:78px; z-index:35; ">
<img src="miniwini.visualEditor/top_miriimg.gif" width="80" height="80">
</div>





<div id="Layer1" style="position:absolute; left:28px; top:90px; width:84px; height:84px; z-index:1; background-color: #888888; layer-background-color: #888888; ">

</div>



<div id="Layer2" style="position:absolute; left:125px; top:107px; width:156px; height:32px; z-index:1">
<input type="file" name="filetoupload" onchange='fnChgImg()'>
</div>


<br>
<p align="center">
<input type="hidden" name="MAX_FILE_SIZE" value="<?echo $size_bytes; ?>">
<br>
<input type="Submit" name="uploadform" value="업로드 !" onfocus="this.blur();">
&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="close" value=" 닫기 " onclick="window.close();opener.upload.checked=false;" onfocus="this.blur();">
</p> </form>



<form name=write1>
<?

}
echo "<hr>현재 <b> -<font color=#6F6FE6>".$member[name]."</font>- </b>님의 폴더에 있는 파일목록:<br>";
?>
</td></tr>
</table>
<script type="text/javascript">
function sendtoclipboard(s)
{
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("Text", s);
alert('파일의 주소가 클립보드에 복사됐습니다.\n\nCtrl+v로 붙어넣기 하세요');
}
else
{
temp = prompt('이 파일의 주소입니다. Ctrl+C를 눌러 클립보드로 복사하세요', s);
}
}

function pop_win(img)
{
a_win = window.open("view_img.php?img=" + img,"popwin", "width=520 ,height=400,resizable=yes,scrollbars=no");
a_win.focus();
}

function delete_file(what)
{

var response = confirm('삭제된 파일은 복원이 불가능합니다\n\n삭제하시겠습니까?');

if (response == true)
{

window.location.href = what;
}
else
{


}
}

</script>

<table cellspacing="1" width=380 align=center style="TABLE-LAYOUT: fixed">
<tr><td bgcolor="#C1BEB5" width="40" align="center"><SPAN style="FILTER: dropshadow(color=#dedede, offx=1, offy=1, positive=1); WIDTH: auto; HEIGHT: 6px"><FONT color=#FFFFFF>보기</FONT></SPAN></td>
<td bgcolor="#C1BEB5" width="170" align="center"><SPAN style="FILTER: dropshadow(color=#dedede, offx=1, offy=1, positive=1); WIDTH: auto; HEIGHT: 6px"><FONT color=#FFFFFF>파일이름</FONT></SPAN></td>
<td bgcolor="#C1BEB5" width="90" align="center"><SPAN style="FILTER: dropshadow(color=#dedede, offx=1, offy=1, positive=1); WIDTH: auto; HEIGHT: 6px"><FONT color=#FFFFFF>크기</FONT></SPAN></td>
<td bgcolor="#C1BEB5" width="40" align="center"><SPAN style="FILTER: dropshadow(color=#dedede, offx=1, offy=1, positive=1); WIDTH: auto; HEIGHT: 6px"><FONT color=#FFFFFF>삽입</FONT></SPAN></td>
<td bgcolor="#C1BEB5" width="40" align="center"><SPAN style="FILTER: dropshadow(color=#dedede, offx=1, offy=1, positive=1); WIDTH: auto; HEIGHT: 6px"><FONT color=#FFFFFF>삭제</FONT></SPAN></td>
</tr>
<tr><td height="2"></td></tr>
<?
$file_list=array();
$rep=opendir($upload_dir);
while ($file = readdir($rep)) {
if($file != '..' && $file !='.' && $file !=''){

if (($extlimit == "yes") && in_array_cin(substr($file, -4),$limitedext) == true){


$file_list[]=$file;


}
}
}

// echo $file_list[5];
$file_list1 = array_reverse($file_list);
if ($page == "") $page = 1;
$j = sizeof($file_list);
$start_index = ($page - 1) * 5;
$i = $start_index;
if ($j > 5) { if (($page * 5) < $j) { $j= $i + 5; }}

for ( $i; $i < $j; $i++ ) {

if (substr ($index_url, -1) == "/") {
$file_add = $index_url.$upload_dir.$file_list1[$i];
$file_del = $index_url."mw_upload.php";
} else {
$file_add = $index_url."/".$upload_dir.$file_list1[$i];
$file_del = $index_url."/mw_upload.php";
}


echo "<tr><td width=40><a href=\"javascript:pop_win('$file_add')\" title='새창에서 원본크기로 미리보기' onfocus=\"this.blur();\"> <img src=\"./phpThumb/phpThumb.php?src=../$upload_dir$file_list1[$i]&w=40&h=40&iar=1\" width=40 height=40 border=0></a> </td><td width=170>$file_list1[$i]</td>";

$file_size = filesize($upload_dir."".$file_list1[$i]);

if ($file_size >= 1048576)
{
$show_filesize = number_format(($file_size / 1048576),2) . " MB";
}
elseif ($file_size >= 1024)
{
$show_filesize = number_format(($file_size / 1024),2) . " KB";
}
elseif ($file_size >= 0)
{
$show_filesize = $file_size . " bytes";
}
else
{
$show_filesize = "0 bytes";
}

echo "<td align=center width=90> $show_filesize </td>";
echo "<td align=center width=40><a href=\"javascript:opener.imgUrl.value='$file_add';opener.upload.checked=false;window.close();\" title='이미지를 게시판에 삽입합니다' onfocus=\"this.blur();\"><font color=#345A87>삽입</font></a>";
// echo "<a href=\"javascript:sendtoclipboard('$file_add')\" title='삽입하지않고 주소만 복사하기' onfocus=\"this.blur();\">(URL)</a></td>";
echo "<td align=center width=40><a href=\"javascript:delete_file('$file_del?delete=$file_list1[$i]')\" title='파일을 삭제합니다' onfocus=\"this.blur();\"><font color=#FF6F6F>삭제</font></a></td></tr>";

}

closedir($rep);
clearstatcache();

$total_page = ceil(sizeof($file_list) / 5);
$page_list = pageLink($total_page, $page, 10, "$_SERVER[PHP_SELF]?");
?>


</table>
<table cellspacing="0" width=380 align=center bgcolor=#C1BEB5><tr><td height="1"></td></tr></table>
<table cellspacing="0" width=380 align=center bgcolor=#EBEAE7><tr><td colspan=4 height=20 valign=bottom>page: <?=$page_list?></td></tr></table>

<div id="Layer1" style="position:absolute; left:380px; top:190px; width:20px; height:20px; z-index:1; background-color: #EBEAE7; layer-background-color: #EBEAE7; border: 1px none #000000;"></div>


<?


for($i=$total_page;$i>=$page;$i++)
{
if ($i == $page){


if ($page > 1){echo "<div id='Layer1' style='position:absolute; left:280px; top:190px; width:280px; height:180px; z-index:30'><font size=2 style='BACKGROUND-COLOR: #ff0000' color=white>&nbsp;".$page."&nbsp;</font>"; $page = $page-1; echo ("<a href={$_SERVER['PHP_SELF']}?page=$page onfocus=this.blur();><font size=2>◀Prev</font></a>");}
else{}


}else{

if($page > 1){echo "<div id='Layer1' style='position:absolute; left:280px; top:190px; width:280px; height:180px; z-index:30'><font size=2 style='BACKGROUND-COLOR: #ff0000' color=white>&nbsp;".$page."&nbsp;</font>"; $page = $page-1; echo ("<a href={$_SERVER['PHP_SELF']}?page=$page onfocus=this.blur();><font size=2>◀Prev</font></a>");$page = $page+1;}

if ($page > $total_page ){$page = $page-1; echo ("<a href={$_SERVER['PHP_SELF']}?page=$page onfocus=this.blur();><font size=2>◀Prev</font></a>"); }
else {

if($page > 1){$page=$page+1;echo (" <a href={$_SERVER['PHP_SELF']}?page=$page onfocus=this.blur();><font size=2>Next▶</font></a>");}
if($page = 1){echo "<div id='Layer1' style='position:absolute; left:280px; top:190px; width:280px; height:180px; z-index:30'><font size=2 style='BACKGROUND-COLOR: #ff0000' color=white>&nbsp;".$page."&nbsp;</font>";$page=$page+1;echo ("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href={$_SERVER['PHP_SELF']}?page=$page onfocus=this.blur();><font size=2>Next▶</font></a>");}

}


}

if ($i >= $MaxPage) break;

}

if ($page < $MaxPage && $page <= $MaxPage - 1);
else


?>




<script>
function keycontrol(){

if(event.keyCode == 39)

{

<? if ($page == $total_page-1)$page=$total_page;?>
var page=<?=$page?>;
location.href = "?page="+page;
}



if(event.keyCode == 37)

{

<?if ($page == TRUE or $page == 1){$page=1;}?>

location.href = "?page=<?=$page?>";
}




}


</script>



</div>




<input type="hidden" name="value02" value="<?=$file_add?>">
</form>

</body>
</html>

첨부파일

130923_upload2.jpg (104.4 KB)
0회 2013-09-23 22:27
|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
12년 전 조회 1,536
12년 전 조회 2,036
12년 전 조회 1,981
12년 전 조회 1,527
12년 전 조회 830
12년 전 조회 954
12년 전 조회 3,006
12년 전 조회 1,613
12년 전 조회 1,542
12년 전 조회 1,822
12년 전 조회 1,641
12년 전 조회 650
12년 전 조회 1,532
12년 전 조회 980
12년 전 조회 975
12년 전 조회 3,185
12년 전 조회 1,297
12년 전 조회 1,531
12년 전 조회 842
12년 전 조회 1,582
🐛 버그신고