Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a temporary file with .pdf extension php tempnam

Tags:

php

Is it possible to create a .pdf file extension when using tempname? I need to send an e-mail with a file created using tempname. (I can send the file, but I need the .pdf extension)

like image 334
Chris Muench Avatar asked Apr 22 '11 18:04

Chris Muench


1 Answers

$tempname = tempnam('', 'report_');
rename($tempname, $tempname .= '.pdf');

// now use the new filename as you wish
var_dump($tempname, is_file($tempname));

By default such files are created with the strictest level of privileges possible. Typically they're only readable by the current user. It may be necessary to make these files group-readable:

chmod($original, 0640);

Or even world-readable, although this is inadvisable:

chmod($original, 0644);
like image 122
sanmai Avatar answered Sep 26 '22 22:09

sanmai