이미지 파일 저장하고, 자동출력하기 > 그누4 질문답변

그누4 질문답변

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

이미지 파일 저장하고, 자동출력하기 정보

이미지 파일 저장하고, 자동출력하기

본문

인터넷 서핑중 우예우예 하다 아래 소스를 찾아 이미지업로드 폼에 이미지를 넣고 확인을 누르면

아래의 소스가 적용되어진 페이지로 이동이 되는데

지정한 폴더에 이미지가 저장은 잘됩니다.

근데...저장한 이미지를 변수를 이용해서 <img src="변수명"> 이렇게만 하면 저장된 이미지가 떳으면 좋겠는데...

온갖 -- ;;수를 써봐도 출력이 안되네요~!!!

<?
$sub_menu = "400300";
include_once("./_common.php");

if ($is_admin != "super")
    alert("최고관리자만 접근 가능합니다.");


$dir = "$g4[path]/data/file/mtimg/"; //저장될 폴더 경로(끝에 '/'슬래시 꼭 붙여주세요...^^)

$varName = "mt_img"; //이전 페이지에서 설정된 file 변수명
$allowExt = "jpg,gif,png"; //업로드 가능한 확장자 (,)콤마로 구분

$prefix = time(); //파일명 앞에 자동으로 붙을 단어

 

function goBack($msg='', $url='') {
  echo "<script>";
  if($msg) echo 'alert("'.$msg.'");';
  if($url) echo 'location.replace("'.$url.'");';
  else echo 'history.go(-1);';
  echo "</script>";
}


  // php.ini 파일에 설정된 upload_max_filesize 값을 이용해서 업로드 파일이 용량을 초과했는지검사
  $allowSize = intval(substr(ini_get(upload_max_filesize),0,-1)) * 1024 * 1024;
  if($allowSize < $_FILES[$varName][size]) {
      goBack("파일 용량이 허용된 용량을 초과했습니다.");
      exit;
  }

  // 정상적인 방법으로 업로드 된 파일인지 검사 후 정상이면 파일 업로드 처리
  if(is_uploaded_file($_FILES[$varName][tmp_name])) {
      // 확장자 검사
      $ext = substr(strrchr($_FILES[$varName][name],"."),1);
      if($ext) {
        $allow = explode(",",$allowExt);
        if(is_array($allow)) $check = in_array($ext,$allow);
        else $check = ($ext == $allow) ? true : false;
      }
      if(!$ext || !$check) {
        goBack("업로드 불가능한 확장자 입니다.");
        exit;
      }

      // 파일명 생성 및 존재하는지 검사
      $newfile = $_FILES[$varName][name];
      if(file_exists($dir.$newfile)) {
        goBack("같은이름의 화일이 있습니다. 화일명을 변경하고 업로드 하시기 바랍니다.");
        exit;
      }

      // $dir 에 파일 저장
      if(!move_uploaded_file($_FILES[$varName][tmp_name], $dir.$newfile)) {
        goBack("파일 업로드에 실패했습니다.");
        exit;
      }
      if(!chmod($dir.$newfile,0707)) {
        goBack("퍼미션변경에 실패했습니다.");
        exit;
      }
  }

 

  echo "<br>실제파일명 : ".$_FILES[$varName][name]."<br>저장된 파일명 : ".$newfile;
mysql_query("update $g4[mt_table] set mtlogo1 = '".$_FILES[$varName][name]."', mt_img = '".$newfile."' where no = '".$no."'");
goto_url("./imgupload.php");
?>
  • 복사

댓글 전체

if(!move_uploaded_file($_FILES[$varName][tmp_name], $dir.$newfile)) {

여기서 $dir.$newfile로 저장이 됐다면

이미지가 뜰 텐데요.

같은 php 파일에서 하신 거 아닌가요?
관리자화면에서 파일 업로드를 하고 출력은 메인에서 합니다...!!
<img src="<?=$dir.$newfile?>" /> 이렇게 먹이면

<IMG src="http://localhost/"> 내용이 나오네요
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

include_once("$g4[path]/head.sub.php");
include_once("$g4[path]/lib/outlogin.lib.php");
include_once("$g4[path]/lib/poll.lib.php");
include_once("$g4[path]/lib/visit.lib.php");
include_once("$g4[path]/lib/connect.lib.php");
include_once("$g4[path]/lib/popular.lib.php");
//print_r2(get_defined_constants());

// 사용자 화면 상단과 좌측을 담당하는 페이지입니다.
// 상단, 좌측 화면을 꾸미려면 이 파일을 수정합니다.

$table_width = 1004;
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML4.0 transitional//EN">
<head>
<title>MalzaTemplate5</title>

<style type="text/css">
body{ font-family: "돋음", "굴림","Arial"; margin:0; padding:0; font-size:11px;}
#menumargin { padding:10px; }
.ltbody{
width:575px;
margin-bottom:10px;
}
.ltleft{
margin-bottom:10px;
width:282px;
float:left;
}
.ltright{
margin-bottom:10px;
width:282px;
float:right;
}
</style>
</head>

<body>

<!--상단메뉴 홈으로,즐겨찾기등등-->
<table align="center" cellpadding="0" cellspacing="0" width="1025" height="40">
    <tr>
        <td background="<?=$g4[path]?>/img/topbg.gif" style="padding:0 10px;">
            <?=$mt['mt_topmenu']?>
        </td>
    </tr>
</table>

<table align="center" cellpadding="0" cellspacing="0" width="1025" height="100" background="<?=$g4[path]?>/img/titlebg.gif">
    <tr>
        <td background="<?=$g4[path]?>/img/titlebg.gif" width="400" style="padding:0 10px;">
<a href="<?=$g4[path]?>"><?=$mt['mt_title']?></a>
<br><?=visit("basic"); // 방문자수 ?>
        </td>
        <td width="225">
<p><img src="<?=$g4[path]?>/img/logo.gif"><img src="<?=$dir.$newfile?>" /></p>
        </td>
        <td background="<?=$g4[path]?>/img/titlebg.gif" width="400">
광고관련
        </td>
    </tr>
</table>

<table align="center" cellpadding="0" cellspacing="0" width="1025" height="40" bgcolor="#333333">
    <tr>
        <td id="menumargin">
            <?=$mt['mt_menu']?>
        </td>
    </tr>
</table>
<table align="center" cellpadding="0" cellspacing="0" width="1025" style="margin-top:10;">
    <tr valign="top">
        <td width="200" height="252">
<?=gbcRF_menu('submenu', $gr_id);//(skin_dir, $gr_id)그룹,게시판,분류 통합 라이브러리 스킨, 그룹값 없다면 전체그룹?>
        </td>
        <td width="10" height="252">
        </td>
        <td width="575" height="252">








메인뿐 아니라 전체 페이지에 동일하게 출력되는 부분입니다.
<p><img src="<?=$g4[path]?>/img/logo.gif"><img src="<?=$dir.$newfile?>" /></p>
        </td>
여기군요.
$dir = "$g4[path]/data/file/mtimg/
$newfile = $_FILES[$varName][name];
파일 올릴 때 파일 명을 따로 저장하지 않으니까


<img src="<?="$g4[path]/data/file/mtimg/올릴때 파일명"?>" />

이렇게밖에 안 되겠네요.
© SIRSOFT
현재 페이지 제일 처음으로