디비내용을 엑셀 파일로 다운로드 시키는 방법

웹페이지 상의 문서를 엑셀이나, 파워포인트, 위드 문서로 변환해 줘야 되는 경우 아래와 같은 방법을 쓰면 상당히 쉽게 해결이 되지요.

만약에 엑셀 파일로 변환을 하고 싶으시면
header(“Content-Type: application/vnd.ms-excel”);
?>
저 부분을 태그 앞에 넣으면 끝나지요.
저 페이지가 호출이 되면 오피스가 깔려있는 사용자들은 저장할것인지 그냥 열것인지를 물어보구여, 안깔려 있는 사용자들은 파일을 다운받을수 있게 되지요.

그럼 워드 파일은
header(“Content-Type: application/msword”);
?>

파워포인트 역시 같은 방법으로
header(“Content-Type: application/vnd.ms-powerpoint”);
?>

그럼 마지막으로 ASP에서는
<%
Response.Buffer = TRUE
Response.ContentType = “application/vnd.ms-excel”
%>

나머지는 응용이 가능하시겠지여?
알고보면 상당히 쉬운방법인데 저 방법을 몰라서 고민하시는 분들이 꽤 되시더라구요.

그럼 도움이 되시길. ^^

다음은 header 내용을 변경해서 excel로 바꾸어 주는 구문입니다.

* excel.php

header(“Content-type: application/vnd.ms-excel”);
header(“Content-Disposition: attachment; filename=test.xls”);
header(“Content-Description: PHP4 Generated Data”);
?>

테스트1 테스트1 테스트1 테스트1
테스트2 테스트2 테스트2 테스트2


실행시켜보세요. 어떻게 되죠? test.xls 이름으로 excel 화일이 다운로드 되죠.
혹 DB내용을 excel형태로 출력해야될 때 유용할거 같습니다.

select 및 radio 버튼 기억하기

안녕하세요..
회원가입이라든지 기타 입력값을 받을때 select 혹은 radio 버튼으로 구성되어 있는 폼에서
수정화면을 보여줘야 할경우 기존에 선택했던 값들을 보여주게 됩니다.
다음과 같이 자바스크립트 코드를 삽입한뒤에 document.onload 를 이용해
입력시 선택했던것들이 선택되게 해봤습니다..

:
:

홈페이지 관리자님……

저 이번에 홈페이지를 하나 만들려고 하는데

사진이 필요해서 그러는데 사진을 사용을 해도 될까 해서 글을 올립니다.

그럼 답변좀 부탁드립니다.

홈페이지가 이쁘네요.

그럼, 수고하세요…

SMTP ?????

/* 파일명 : class.Smtp.php
/* 제작일 : 2002-08-30
/* 제작자 : 하근호(hopegiver@korea.com)
/***************************************/

class Smtp {

var $host;
var $fp;
var $self;
var $lastmsg;
var $parts;
var $error;
var $debug;
var $charset;
var $ctype;

function Smtp($host=”localhost”) {
if($host == “self”) $this->self = true;
else $this->host = $host;
$this->parts = array();
$this->error = array();
$$this->debug = 0;
$this->charset = “euc-kr”;
$this->ctype = “text/html”;
}

// 디버그 모드 : 1
function debug($n=1) {
$this->debug = $n;
}

// smtp 통신을 한다.
function dialogue($code, $cmd) {

fputs($this->fp, $cmd.”
“);
$line = fgets($this->fp, 1024);
ereg(“^([0-9]+).(.*)$”, $line, &$data);
$this->lastmsg = $data[0];

if($this->debug) {
echo htmlspecialchars($cmd).”
“.$this->lastmsg.”
“;
flush();
}

if($data[1] != $code) return false;
return true;

}

// smptp 서버에 접속을 한다.
function smtp_connect($host) {

if($this->debug) {
echo “SMTP($host) Connecting…
“;
flush();
}

if(!$host) $host = $this->host;
if(!$this->fp = fsockopen($host, 25, $errno, $errstr, 10)) {
$this->lastmsg = “SMTP($host) 서버접속에 실패했습니다.[$errno:$errstr]”;
return false;
}

$line = fgets($this->fp, 1024);
ereg(“^([0-9]+).(.*)$”, $line, &$data);
$this->lastmsg = $data[0];
if($data[1] != “220”) return false;

if($this->debug) {
echo $this->lastmsg.”
“;
flush();
}

$this->dialogue(250, “HELO phpmail”);
return true;

}

// stmp 서버와의 접속을 끊는다.
function smtp_close() {

$this->dialogue(221, “QUIT”);
fclose($this->fp);
return true;

}

// 메시지를 보낸다.
function smtp_send($email, $from, $data) {

if(!$mail_from = $this->get_email($from)) return false;
if(!$rcpt_to = $this->get_email($email)) return false;

if(!$this->dialogue(250, “MAIL FROM: $mail_from”))
$this->error[] = $email.”:MAIL FROM 실패($this->lastmsg)”;
if(!$this->dialogue(250, “RCPT TO: $rcpt_to”))
$this->error[] = $email.”:RCPT TO 실패($this->lastmsg)”;
$this->dialogue(354, “DATA”);

$mime = “Message-ID: <".$this->get_message_id().”>
“;
$mime .= “From: $from
“;
$mime .= “To: $email
“;

fputs($this->fp, $mime);
fputs($this->fp, $data);
$this->dialogue(250, “.”);

}

// Message ID 를 얻는다.
function get_message_id() {
$id = date(“YmdHis”,time());
mt_srand((float) microtime() * 1000000);
$randval = mt_rand();
$id .= $randval.”@phpmail”;
return $id;
}

// Boundary 값을 얻는다.
function get_boundary() {
$uniqchr = uniqid(time());
$one = strtoupper($uniqchr[0]);
$two = strtoupper(substr($uniqchr,0,8));
$three = strtoupper(substr(strrev($uniqchr),0,8));
return “—-=_NextPart_000_000${one}_${two}.${three}”;
}

// 첨부파일이 있을 경우 이 함수를 이용해 파일을 첨부한다.
function attach($message, $name=””, $ctype=”application/octet-stream”) {
$this->parts[] = array (“ctype” => $ctype, “message” => $message, “name” => $name);
}

// Multipart 메시지를 생성시킨다.
function build_message($part) {

$msg .= “Content-Type: “.$part[‘ctype’];
if($part[‘name’]) $msg .= “; name=””.$part[‘name’].”””;
$msg .= “
Content-Transfer-Encoding: base64
“;
$msg .= “Content-Disposition: attachment; filename=””.$part[‘name’].””

“;
$msg .= chunk_split(base64_encode($part[‘message’]));
return $msg;

}

// SMTP에 보낼 DATA를 생성시킨다.
function build_data($subject, $body) {

$boundary = $this->get_boundary();

$mime .= “Subject: $subject
“;
$mime .= “Date: “.date (“D, j M Y H:i:s T”,time()).”
“;
$mime .= “MIME-Version: 1.0
“;
$mime .= “Content-Type: multipart/mixed; boundary=””.$boundary.””

“.
“This is a multi-part message in MIME format.

“;
$mime .= “–“.$boundary.”
“.
“Content-Type: “.$this->ctype.”; charset=””.$this->charset.””
“.
“Content-Transfer-Encoding: base64

“.
chunk_split(base64_encode($body)).

–“.$boundary;

$max = count($this->parts);
for($i=0; $i<$max; $i++) {
$mime .= “
“.$this->build_message($this->parts[$i]).”

–“.$boundary;
}
$mime .= “–
“;

return $mime;

}

// MX 값을 찾는다.
function get_mx_server($email) {

if(!ereg(“([._0-9a-zA-Z-]+)@([0-9a-zA-Z-]+.[a-zA-Z.]+)”, $email, $reg)) return false;
getmxrr($reg[2], $host);
if(!$host) $host[0] = $reg[2];
return $host;

}

// 이메일의 형식이 맞는지 체크한다.
function get_email($email) {
if(!ereg(“([._0-9a-zA-Z-]+)@([0-9a-zA-Z-]+.[a-zA-Z.]+)”, $email, $reg)) return false;
return “<".$reg[0].">“;
}

// 메일을 전송한다.
function send($to, $from, $subject, $body) {

if(!is_array($to)) $to = split(“[,;]”,$to);
if($this->self) {

$data = $this->build_data($subject, $body);
foreach($to as $email) {
if($host = $this->get_mx_server($email)) {
$flag = false; $i = 0;
while($flag == false) {
if($host[$i]) {
$flag = $this->smtp_connect($host[$i]);
$i++;
} else break;
}
if($flag) {
$this->smtp_send($email, $from, $data);
$this->smtp_close();
} else {
$this->error[] = $email.”:SMTP 접속실패”;
}
} else {
$this->error[] = $email.”:형식이 잘못됨”;
}
}

} else {

if(!$this->smtp_connect($this->host)) {
$this->error[] = “$this->host SMTP 접속실패”;
return false;
}
$data = $this->build_data($subject, $body);
foreach($to as $email) $this->smtp_send($email, $from, $data);
$this->smtp_close();

}

}

}

/* 사용법
$mail = new Smtp(“self”);
$mail->debug();
$mail->send(“photon0@hanmail.net”, “hopegiver@whois.co.kr”, “이 메일은 정상입니다.”, “정상적인 메일이니 삭제하지 마십시오.”);
*/

?>

목요일 저녁..

9월도 5일이나 지나갔네요.
요 며칠은 몸이 몹시 피곤해서 저녁엔 정신을 못차리고 있지요.
아침엔 새로운 좋은 일 하고, 저녁엔 좀 더 늦게 퇴근하고,
일터는 새학기라 넘 바쁘고.. 그러다 보니..
가끔은 이 일터에서 해방을 하고 싶은 충동이 일어납니다.
저녁엔 몸이 축 늘어진채로 서방을 만나곤 하지요,
일만 아니면 좀 더 생기있는 모습으로 만날 수도 있을텐데 하는 아쉬움..
또, 시간이 많으면 그림공부도, 차공부도 또 맘속에 담아두고 있는 이것 저것들을
차근히 할 수 있을것 같은 그런 아쉬움..
그래서 몇번씩 고민에 고민을 하기도 합니다.
그런데, 이상하죠? 막상 일을 놓으려고 하면 왜 그리 안되는지..
많지는 않지만, 한달에 한번씩 꼬박꼬박 내 손에 쥐어지는 월급도 그렇고,
물론, 스트레스도 쌓이지만, 다른 일터에서 느낄 수 있는 분위기에 활력도 생기고,
일터에서 만나는 동료들도 그렇고,
내가 일을 하고 있구나 하는 자부심과 일에 대한 재미등등..
또 집에서 온종일 시간을 보내야하는 것도 자신이 없고..
참 이유가 많죠?
그런데 요즘 특히 일을 계속 해야하나, 쉬어야하나 하는 남모르는 딜레마에 빠지곤 합니다.
오늘도 축쳐진 모습으로 서방을 보겠네요.
8월까지만해도 같이 퇴근을 햇는데, 제가 퇴근시간이 늦어지는 바람에 이제는
먼저 집에 가서 저를 기둘리지요.
그리고 버스정류장까지 마중을 나온답니다.
오늘도 역시 좀 피곤하지만, 그래도 생기있어보이도록 노력을 해야겠죠?
솔직이 어제는 너무 피곤해서 거울앞에서 눈물까정 쏟아냈답니다.
그런 나에게 짱구춤으로 위로를 해주는 착한 서방..
오늘은 제가 재롱을 떨어야겟네여. 짱구춤으로(?) ㅋㅋ..