0

I export reports as excel using PHP & MySql. I can export and open the file from my localhost using my source code, but unable to do in the server. When I try to export it shows " Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home:/tmp:/usr) in /home/xx/xx.inc.php on line 205." I googled through, but I'm unable get the solution.

$this->_tmpfilename=tempnam("/tmp", "excelreport");

$fh=fopen($this->_tmpfilename, "w+b");

This is the code that used. What's wrong.

3
  • Check your server temp path and necessary folder permissions Commented May 20, 2013 at 9:21
  • What library are you using to create your Excel file? If it uses temporary files, then it should provide some method for you to say where those files are created Commented May 20, 2013 at 9:23
  • I use the php_writeexcel/ written by Johan Commented May 20, 2013 at 12:38

1 Answer 1

0

Your hosting restricts your PHP activity within your home folder. Create a tmp folder within your home folder (i.e. /home/xx/tmp/ ), chmod it 777 to solve this problem.

Note: the /tmp folder is used by the server itself. In shared hosting environment, you are often restricted not to touch the server's system folders ( folders other than /home )

Sign up to request clarification or add additional context in comments.

4 Comments

I tried & still the same warning message
what is the full path of your file ?
/home/xx/public_html/pms/excelreport
then your code should be $this->_tmpfilename=tempnam("/home/xx/public_html/pms/", "excelreport");

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.