Setting the location of a temporary folder

I am working on linux. I made some progresses with search and
highlight app and have a little problem.

I have a script called run.php. What it does is get a pdf file and
highlight the search query by invoking the java code I work on.

if I run command prompt - php run.php, it will works.

But If I do - php app/run.php
It will complain:

Exception:
     Message: mkstemp() failed to create a temporary file.
    at pdftron.PDF.ElementWriter.End(Native Method)
    at pdftron.PDF.ElementWriter.end(ElementWriter.java:100)
    at PDFSearch.CreateHighlightAppearance(PDFSearch.java:68)
    at PDFSearch.CreateHighlightAnnot(PDFSearch.java:92)
    at PDFSearch.main(PDFSearch.java:183)
Exception in thread "main" java.lang.NullPointerException
    at pdftron.PDF.Annot.setAppearance(Annot.java:620)
    at PDFSearch.CreateHighlightAnnot(PDFSearch.java:92)
    at PDFSearch.main(PDFSearch.java:183)

That is because it cannot create temporary files to the directory,
where the current php command execute. i.e. app/

If I set 777 to app/, it will work well, but I will not do it.

I wonder is there any solution to this problem. e.g. only write
temporary file to under app/
----
A: You can use PDFNet::SetTempPath("..my path..") to set the location
of temporary folder to an arbitrary location.