简体   繁体   中英

failed to open stream: Permission denied

I'm developing a web site with php and mysql and dompdf , in one of my forms i have a buttton, the button has to generate a . pdf file and later, send it by email. (on my local host, it can generate the pdf file, but don't send the email. On my web server, i can't create the pdf but the e mail is sended...)

The message I can see is:

Warning: file_put_contents(C:/Inetpub/vhosts/.../dompdf/lib/fonts/log.htm) [function.file-put-contents]: failed to open stream: Permission denied in C:\Inetpub\vhosts\...\dompdf\include\dompdf.cls.php on line 864 
//the mistake in in the `dompdf` class

Warning: file_put_contents(pdf/pdfgenerados/cotizacion.pdf) [function.file-put-contents]: failed to open stream: Permission denied in C:\Inetpub\vhosts\...\list.php on line 116

This is my code:

$codigoHTML=utf8_decode($codigoHTML);
$dompdf=new DOMPDF();
$dompdf->load_html($codigoHTML);
ini_set("memory_limit","128M");
$dompdf->render();
$pdf = $dompdf->output();

file_put_contents("pdf/pdfgenerados/cotizacionnueva.pdf", $pdf);



echo "Cotización generada";


//<<-------------- Send by email------------>>>

$fileat = "pdf/pdfgenerados/cotizacionnueva.pdf";
$fileat_type="pdf";
$fileatname= "Cotización.pdf";

$emailfrom="my-email@hotmail.es";
$emailsubject="Cotización";
$emailmessage="------------ Here you have the pdf file... have a nice day";
$emailto="other_e-mail@gmail.com";//
$headers = "From: $emailfrom";

$file = fopen($fileat,'rb');   
$data = fread($file,filesize($fileat));   
fclose($file); 

$semi_rand = md5(time());   
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";   


$data = chunk_split(base64_encode($data));   
$data . "nn --{$mime_boundary}--n";   

$ok = @mail($emailto, $emailsubject, $emailmessage, $headers);   

  if($ok) {   
  echo " <br/><font face=verdana size=2>The file was successfully sent!</font>";   
  } else {   
  die("Sorry but the email could not be sent. Please go back and try again!");   
  } 

I recieve the email. but i dont recieve the pdf. file

What could I do???

This happens because mPDF trying to write a temporary file on TTFONTDATA folder

You can solve it by giving TTFONTDATA folder write permission 0777 or by Changing the _MPDF_TTFONTDATAPATH path to the Linux temp directory by adding the following line before creating the instance of mPDF

define('_MPDF_TTFONTDATAPATH', sys_get_temp_dir()."/");

you probably don't have access rights in the folder

pdf/pdfgenerados/

Give read/write access to this folder, and also to file cotizacionnueva.pdf , if it exists already

For security reasons, DOMPDF cannot read html files outside of the dompdf root. See line 133 of dompdf_config.inc.php. The path you have to use is the DOMPDF root.

This will work:

  $url = base_path() . '/vendor/dompdf/dompdf/pdfs/email-price-quote.html';
  $dompdf = new Dompdf();
  $dompdf->load_html_file($url);
  $dompdf->render();

I had similiar issues on laravel in production.

Had to set some options manually:

App::make('dompdf.wrapper')
->setOptions([
  'logOutputFile' => storage_path('logs/dompdf.html'),
  'tempDir' => storage_path('fonts'),
  'isRemoteEnabled' => true
])
cd /application/vendor/mpdf/mpdf  
chmod -R 777 ttfontdata/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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