好吧,所以我正在尝试完成以下任务:
我已经收集了一个名为 $ filename 的变量,当我 echo $ filename 时,我得到以下结果。
/skiftrapportPDF/201404/Skiftrapport2014-04-16_125449-Orange.pdf
我的代码
$dir = dirname(__FILE__);
$skift = $_POST['skift'];
$datum = Date("Y-m-d");
$tid = Date("H:i:s");
if($skift=='1')$skift='Svart';if($skift=='2')$skift='Blå';if($skift=='3')$skift='Röd';if($skift=='4')$skift='Orange';
//this is when i have generated my $html
require_once($dir.'/skift_rapport_pdf.php');
require_once($dir.'/include/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for later
$month = date('Ym');
if (!is_dir("skiftrapportPDF/".$month)) {
// dir doesn't exist, make it
mkdir("skiftrapportPDF/".$month);
}
$skift = $_POST['skift'];
$datum = Date("Y-m-d");
$tid = Date("His");
if($skift=='1')$skift='Svart';if($skift=='2')$skift='Blå';if($skift=='3')$skift='Röd';if($skift=='4')$skift='Orange';
$filename = '/skiftrapportPDF/'.$month.'/Skiftrapport'.$datum.'_'.$tid.'-'.$skift.'.pdf';
//I've tried using either of the following....
file_put_contents($filename, $pdf_content);
//Commented to try using file_put_contents()
//$fp = fopen($filename, "a");
//fwrite($fp, $pdf_content);
//fclose($fp);
使用fopen(),fwrite,fclose给了我这个错误:
Warning: fopen(/skiftrapportPDF/201404/Skiftrapport2014-04-16_125449-Orange.pdf) [function.fopen]: failed to open stream: No such file or directory in file.php on line 863
并使用file_put_contents()给了我这个错误。
Warning: file_put_contents(/skiftrapportPDF/201404/Skiftrapport2014-04-16_144631-Orange.pdf) [function.file-put-contents]: failed to open stream: No such file or directory in file.php on line 857
答案 0 :(得分:0)
您只需要重写以下行。
使用完整服务器路径或删除开始' /'来自档案。
1)像这样使用
$filename = $_SERVER['DOCUMENT_ROOT'] . '/skiftrapportPDF/'.$month.'/Skiftrapport'.$datum.'_'.$tid.'-'.$skift.'.pdf';
或写下以下方式,
$filename = 'skiftrapportPDF/'.$month.'/Skiftrapport'.$datum.'_'.$tid.'-'.$skift.'.pdf';
这两个都适合你。试试其中任何一个