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

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

QA

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

답변 1

본문

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

버추얼박스로 가상머신 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();
    
?>

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 604
© SIRSOFT
현재 페이지 제일 처음으로