2016-11-05 6 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

私が見る1つの問題は、if文で1つの「=」です。 '='は代入用で、 '=='は比較用です。

if($d = mysql_fetch_array($result)) 

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

にEDITを変更してみてください:しかし、私はそれはかなりのいずれかに動作するとは思いません。ライン14上のselect.phpでD私はこのようなエラーが私を助けてください取得しています:私は

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

未定義の変数をしようとするだろう。 – sudha

+0

私の2番目の解決策を試しましたか? $ 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.'; 
       } 
関連する問題