簡體   English   中英

嘗試將pdf寫入文件目錄:獲取內部服務器錯誤500

[英]Trying to write a pdf to file directory: Get internal server error 500

我正在編寫一個程序,該程序填充pdf模板(使用fpdf),然后捕獲屏幕快照以預覽給用戶。

Imagemagick似乎需要文件系統中的現有文件來捕獲預覽圖像,這意味着我需要將pdf保存到目錄。

我按照說明(位於此處: 無法使用FPDF將文件保存到目錄 )更改文件夾的權限,以使我能夠寫入目錄,但是每當我現在運行php頁面時,我都會得到:

我有755作為默認權限,並且由於我只是在測試,並且此文件夾不是特別重要,因此我嘗試將其更改為777。

500 Server Error
A misconfiguration on the server caused a hiccup. Check the server logs, fix the problem, then try again. 

URL: *Full URL*
Dangerously writable: [*File path on server*]
FIXED

在該錯誤之后,我檢查了該文件夾,權限又恢復為755,並且沒有error_log文本文件,因此我不確定如何調試它,因為google顯示服務器錯誤500是通用捕獲。

托管服務是bluehost.com

這是代碼:

<?php
// Library imports
require_once(dirname(__FILE__)."/lib/fpdf/fpdf.php");
require_once(dirname(__FILE__)."/lib/fpdi/fpdi.php");
// End of imports


//OpenCnxn
mysql_connect(*the approrpiate stuff*) or die(mysql_error());
mysql_select_db(*the appropriate stuff*) or die(mysql_error());

//Query DB and calculate number of rows
$query = "Select ProfilePicture from Users where UserID = 1"; 
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

$filename = "template.pdf";

$pdf = new FPDI();
$pdf->AddPage();

// import the template PFD
$pdf->setSourceFile($filename);

// select the first page
$tplIdx = $pdf->importPage(1);

// use the page we imported
$pdf->useTemplate($tplIdx);

//Image insertion
for($i=0;$i<$num_results;$i++){
   $row = mysql_fetch_array($result);
   $pdf->Image(htmlspecialchars(stripslashes($row['ProfilePicture'])), 13, 13, 35, 25);
}

$pdf->Output('testdocument.pdf', 'F');

當權限為755且將最后一行更改為下載而不是保存文件時,以上代碼按預期工作,即:

$pdf->Output(); //OR
$pdf->Output('testdocument.pdf', 'D');

經過Hosting IT的仔細檢查。

之所以發生這樣的消息,是因為在根級別已禁止更改為高於755的任何權限級別。

感謝您的耐心等待。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM