php 다운로드된 파일이 열리고도 표시가 재대로 안되는 오류

php 다운로드된 파일이 열리고도 표시가 재대로 안되는 오류

QA

php 다운로드된 파일이 열리고도 표시가 재대로 안되는 오류

본문

물어볼곳이 없어서 고심끝에 이쪽에한번 문의해봅니다

버추얼박스로 가상머신 centos 6.5 윈 7 에서 하고있습니다.

 djqfhem3743524199_1550145514.2833.png3743524199_1550145524.4189.png

 

3743524199_1550145712.5846.png

 

3743524199_1550145728.5304.png

이 질문에 댓글 쓰기 :

답변 1

코드소스입니다 ㅠㅠ

 


<?php
 
    header("Content-type: text/html; charset=utf-8");
 
    if(!$_GET['num'])
    {
        echo "<script>alert('이상하게 접근하셨습니다;;');";
        echo "history.back();</script>";
    }
    
    @ $db = new mysqli('DB호스트', 'DB계정명', 'DB계정비밀번호', '사용할DB');
    if(mysqli_connect_errno())
    {
        echo "DB connect error";
        exit;
    }
    
    $query = "select name, hash from ftp where num=".$_GET['num'];
    $result = $db->query($query);
    if(!$result)
    {
        echo "query error";
        exit;
    }
    $result = $result->fetch_assoc();
    
    $dir = "./files/";
    $filename = $result['name'];
    $filehash = $result['hash'];
    
    if(file_exists($dir.$filehash))
    {
            header("Content-Type: Application/octet-stream");
            header("Content-Disposition: attachment; filename=".$filename);
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".filesize($dir.$filehash));
 
            $fp = fopen($dir.$filehash, "rb");
            while(!feof($fp))
            {
                echo fread($fp, 1024);
            }
            fclose($fp);
            
            $query = "update ftp set down=(down+1) where num=".$_GET['num'];
            $result = $db->query($query);
            if(!$result)
            {    
                echo "down counter update error";
                exit;
            }
    }
    else
    {
            echo "<script>alert('파일이 없습니다.);";
            echo "history.back();</script>";
            exit;
    }
    $db->close();
    
?>

답변을 작성하시기 전에 로그인 해주세요.
전체 14,969
QA 내용 검색
filter #php ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT