4

When a files is upload via a form its location is somewhere that is writable by the webserver but NOT in the current application folder. The reason I like this is:

  1. The application doesn't have to have a publicly writable folder
  2. If you only need it temporally (such as attaching to an e-mail) then this is a great location

Is there a way to have access to this location via TCPDF when saving a file?

Chris Muench
  • 17,444
  • 70
  • 209
  • 362

1 Answers1

10

If you want to use the very same location where uploads end up:

$tmp = ini_get('upload_tmp_dir');

But you should use sys_get_temp_dir() and just '/tmp' as fallback anyway.

And you know, just pass that as parameter to your save function $TCPDF->Output("$tmp/file.pdf", "F");

mario
  • 144,265
  • 20
  • 237
  • 291
  • Is it pretty reliable that sys_get_temp_dir will always be writable? – Chris Muench Apr 22 '11 at 15:14
  • If the server is severely misconfigured, not. In all other cases, yes. It defaults just to `/tmp` most of the time anyway. – mario Apr 22 '11 at 15:15
  • @mario - just curious, when is the file stored in "/tmp" removed from the server in this case? Does this have to be done manually? – JM4 Jul 17 '13 at 15:26
  • @JM4 That indeed requires manual care. Depending on server setup there are usually cron jobs which purge older files. I regularily set some up for local temp dirs. In OPs example there should be an implicit unlink() in the same script. – mario Jul 17 '13 at 18:20
  • Maybe check [http://stackoverflow.com/questions/12304553/tcpdf-save-file-to-folder/19316809#19316809](http://stackoverflow.com/questions/12304553/tcpdf-save-file-to-folder/19316809#19316809) – KarlosFontana Oct 11 '13 at 11:22