简体   繁体   English

尝试将pdf写入文件目录:获取内部服务器错误500

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

I'm writing a program that fills in a pdf template (using fpdf) then captures a screenshot to preview to the user. 我正在编写一个程序,该程序填充pdf模板(使用fpdf),然后捕获屏幕快照以预览给用户。

Imagemagick seems to need a existing file in the filesystem to capture the preview image meaning I need to save the pdf to directory. Imagemagick似乎需要文件系统中的现有文件来捕获预览图像,这意味着我需要将pdf保存到目录。

I followed the directions (found here: Cannot Save File to directory using FPDF ) to change permission on the folder to enable me to write to the directory but whenever I run my php page now I get: 我按照说明(位于此处: 无法使用FPDF将文件保存到目录 )更改文件夹的权限,以使我能够写入目录,但是每当我现在运行php页面时,我都会得到:

I have 755 as the default permission, and since I'm just testing and this folder isn't particularly mission critical I tried to change to 777. 我有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

I checked the folder after that error and permission reverts back to 755 and there is not a error_log text file so I'm not sure how to debug this as google reveals server error 500 is a generic catch all. 在该错误之后,我检查了该文件夹,权限又恢复为755,并且没有error_log文本文件,因此我不确定如何调试它,因为google显示服务器错误500是通用捕获。

The hosting service is bluehost.com 托管服务是bluehost.com

Here is the code: 这是代码:

<?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');

The above code works as expected when the permission is on 755 and when the last line is changed to download instead of file save ie: 当权限为755且将最后一行更改为下载而不是保存文件时,以上代码按预期工作,即:

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

Double checked with Hosting IT. 经过Hosting IT的仔细检查。

Such message are happening because changing to any permission level higher than 755 has been disabled at the root level. 之所以发生这样的消息,是因为在根级别已禁止更改为高于755的任何权限级别。

Thank you for your patience. 感谢您的耐心等待。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM