웹프로그래밍

Global It Leader!!


PHP


 
 

간단 오피스 뷰어 테스트 소스

페이지 정보

작성자 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 172회 작성일 24-07-07 23:39

본문

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['file'])) {

    $uploadDir = 'uploads/';

    $uploadFile = $uploadDir . basename($_FILES['file']['name']);


    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {

        echo "파일이 성공적으로 업로드되었습니다.\n";

        echo "<a href='viewer.php?file=" . urlencode($uploadFile) . "'>파일 보기</a>";

    } else {

        echo "파일 업로드에 실패하였습니다.\n";

    }

}

?>


<!DOCTYPE html>

<html lang="ko">

<head>

    <meta charset="UTF-8">

    <title>파일 업로드</title>

</head>

<body>

    <form enctype="multipart/form-data" action="" method="POST">

        <input type="file" name="file" />

        <input type="submit" value="업로드" />

    </form>

</body>

</html>



<?php
$file = isset($_GET['file']) ? urldecode($_GET['file']) : null;
if (!$file || !file_exists($file)) {
    die('유효한 파일이 아닙니다.');
}

$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$officeList = [".pdf", "docx", "docm", "dotm", "dotx", ".doc", "xlsx", "xlsb", ".xls", "xlsm", "pptx", "ppsx", ".ppt", "pptm", "potm", ".ppm", "potx", "ppsm"];

if (!in_array(".$extension", $officeList)) {
    die('지원하지 않는 파일 형식입니다.');
}
?>

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>파일 뷰어</title>
</head>
<body>
<?php if ($extension == 'pdf'): ?>
    <embed src="<?= htmlspecialchars($file) ?>" type="application/pdf" width="100%" height="600px" />
<?php elseif (in_array(".$extension", [".docx", ".doc", ".pptx", ".ppt", ".xlsx", ".xls"])): ?>
    <iframe src="https://view.officeapps.live.com/op/view.aspx?src=<?= urlencode('http://yourdomain.com/' . $file) ?>" width="100%" height="600px"></iframe>
<?php else: ?>
    <p>해당 파일 형식의 뷰어가 없습니다.</p>
<?php endif; ?>
</body>
</html>

댓글목록

등록된 댓글이 없습니다.

전체 92
게시물 검색
PHP 목록
번호 제목 글쓴이 조회 날짜
92 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 66 01-06
91 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 65 12-22
90 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 145 10-09
89 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 157 10-09
88 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 157 10-08
87 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 197 09-03
86 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 184 07-26
85 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 189 07-26
84 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 183 07-07
열람중 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 173 07-07
82 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 175 06-15
81 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 226 04-23
80 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1624 03-29
79 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4067 03-26
78 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1804 03-26
77 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1610 03-17
76 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2336 11-28
75 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2531 08-11
74 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2144 08-10
73 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2766 08-02