2017-05-08 19 views
-2

管理者がPDFをアップロードし、ユーザーがそのPDFをダウンロードする管理ページの開発。ユーザーのダウンロードPDFた後、PDFにパスワードを尋ねる必要があり、PHPで自動的にPDFにパスワードを設定して、そのPDFを管理パスワード保護PHPの場合

で設定すべきではありませんどのようにこれは私の管理ページのコードである

move_uploaded_file($tmp_name, $location); 
if (copy($location, $location1)) { 

    $query = mysqli_query($conn, "SELECT * FROM `at_uploads` WHERE name='$name1'"); 
    if (mysqli_num_rows($query) > 0) { 

     echo("<SCRIPT LANGUAGE='JavaScript'> 
        window.alert('File already exists with that name') 
        window.location.href='upload'; 
         </SCRIPT>"); 
    } 
} 

これは私のユーザーのダウンロードページ

if(isset($_GET['dow'])) { 

$filepath1 = $_GET['dow']; 

$query = mysqli_query($conn, "SELECT * FROM `at_uploads` WHERE filepath1 ='$filepath1'"); 
while (($row = mysqli_fetch_array($query))) { 

    $name=$row['name']; 
    $location = "C:/wamp/www/school/admin/files/" . $name; 
    header('Content-Type: application/pdf'); 

    header('Content-Disposition: attachment; filename="' . basename($location) . '"'); 
    header('Content-Length: ' . filesize($location)); 
    readfile($location); 
     } 
    } 

である私がどこかわかりませんpdfのパスワードを設定する

+0

あなたは必要なものをより具体的にする必要があります。また、ソースコードと誤った箇所を提供することができれば、これはもっと速くなります。あなたのエラーログ – Akintunde007

+0

どのライブラリを使っていますか –

+0

しかし、管理者がパスワードを設定できない場合、どのようにパスワードを知っていますか?または、ユーザーがpdfとパスワードを分離したものにする。ファイルの直接ダウンロードとメールごとのパスワード? –

答えて

0

どのライブラリを使用していますか? FPdiを使用している場合は、以下の機能を使用してください。

<?php 

function pdfEncrypt ($origFile, $password, $destFile){ 
//include the FPDI protection http://www.setasign.de/products/pdf-php-solutions/fpdi-protection-128/ 
require_once('fpdi/FPDI_Protection.php'); 

$pdf =& new FPDI_Protection(); 
// set the format of the destinaton file, in our case 6×9 inch 
$pdf->FPDF('P', 'in', array('6','9')); 

//calculate the number of pages from the original document 
$pagecount = $pdf->setSourceFile($origFile); 

// copy all pages from the old unprotected pdf in the new one 
for ($loop = 1; $loop <= $pagecount; $loop++) { 
    $tplidx = $pdf->importPage($loop); 
    $pdf->addPage(); 
    $pdf->useTemplate($tplidx); 
} 

// protect the new pdf file, and allow no printing, copy etc and leave only reading allowed 
$pdf->SetProtection(array(),$password); 
$pdf->Output($destFile, 'F'); 

return $destFile; 
} 

//password for the pdf file 
$password = '[email protected]'; 

//name of the original file (unprotected) 
$origFile = 'yourfilename.pdf'; 

//name of the destination file (password protected and printing rights removed) 
$destFile ='yourfilename.pdf'; 

//encrypt the book and create the protected file 
pdfEncrypt($origFile, $password, $destFile); 
?> 
+0

私はこれを試してみました – karthik

関連する問題