2016-11-05 7 views
0

데이터베이스에서 pdf 파일을 가져 오는 중 오류가 발생했습니다. 아래에 제 코드가 나와 있습니다. 내 코드를 검토하고 귀중한 제안을 보내주십시오. 그리고 출력을 열지 못했습니다. 문서. 제발 도와주세요.PHP에서 데이터베이스에서 PDF 파일 가져 오기

<?php 
    $server = 'localhost'; 
    $user = 'root'; 
    $pass = ''; 
    $db = 'upload'; 

// Connect to Database 
    $connection = mysql_connect($server, $user, $pass) or die ("Could not connect to server ... \n" . mysql_error()); 
    mysql_select_db($db) or die ("Could not connect to database ... \n" . mysql_error()); 
    $id = intval($_GET['id']); 
    $file= 'SELECT `name`,`size`, `created`,`data` FROM `upload`'; 
    $result = mysql_query($file); 

    if($d = mysql_fetch_array($result)) 
    { 
     $file = $d['name']; 
     header('Content-type: application/pdf'); 
     header("Content-Disposition: inline; name=".$row['name']); 
     header('Content-Transfer-Encoding: binary'); 
     header('Content-Length: ' . size($file)); 
     header('Accept-Ranges: bytes'); 
     header("Location: $file"); 
     @readfile($file); 
    } 
    else{ 
     echo'No file with the specified ID exists'; 
    } 
?> 

답변

0

하나의 문제는 if 문에서 하나의 "="입니다. '='는 대입을위한 것이고 '=='는 비교를위한 것입니다.

시도

if($d = mysql_fetch_array($result)) 

편집

if($d == mysql_fetch_array($result)) 

에 변경 : 그러나, 나는 그것이 매우 중 하나가 작동합니다 생각하지 않습니다. 나는

$d = mysql_fetch_array($result); 
if ($d === true) 
+0

정의되지 않은 변수를 시도 할 것입니다 : D를 select.php에 라인 (14) 내가 좀 도와주십시오과 같은 오류가 점점 오전에. – sudha

+0

두 번째 솔루션을 사용해 보셨습니까? 그것은 $ d를 지정/정의해야합니다. – infinigrove

+0

다른 곳으로 직접가는 경우 .... – sudha

0
if($result) { 
     // Make sure the result is valid 
       if($result->num_rows == 1) { 

       $row = mysqli_fetch_assoc($result); 
       header('Content-type: application/pdf'); 
       header("Content-Disposition: inline; name=".$row['name']); 
       header('Content-Transfer-Encoding: binary'); 
       header("Content-Length: ". $row['size']); 
       header('Accept-Ranges: bytes'); 
      // Print data 
       @readfile($row['data']); 
       echo $row['data']; 
       } 
       else { 
         echo 'Error! No image exists with that ID.'; 
       } 
관련 문제