Bug #9511 Shared /tmp dir assumed
# Added setTmpDir for people that have openbase_dir. # If people try to use the class with out setting a tmp dir # but do have open_basedir on then the class fails silently at the moment git-svn-id: https://svn.php.net/repository/pear/packages/Spreadsheet_Excel_Writer/trunk@241286 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
fa302dd9c5
commit
c810d23f97
|
|
@ -391,6 +391,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
|
||||||
//$this->ext_sheets = array();
|
//$this->ext_sheets = array();
|
||||||
$this->_filehandle = '';
|
$this->_filehandle = '';
|
||||||
$this->_using_tmpfile = true;
|
$this->_using_tmpfile = true;
|
||||||
|
$this->_tmp_dir = '';
|
||||||
//$this->fileclosed = 0;
|
//$this->fileclosed = 0;
|
||||||
//$this->offset = 0;
|
//$this->offset = 0;
|
||||||
$this->_xls_rowmax = $rowmax;
|
$this->_xls_rowmax = $rowmax;
|
||||||
|
|
@ -473,17 +474,50 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
|
||||||
*/
|
*/
|
||||||
function _initialize()
|
function _initialize()
|
||||||
{
|
{
|
||||||
|
if ($this->_using_tmpfile == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_tmp_dir === '' && ini_get('open_basedir') === false) {
|
||||||
|
//return new PEAR_Error('open_basedir restriction in effect, please use setTmpDir() for this to work');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Open tmp file for storing Worksheet data
|
// Open tmp file for storing Worksheet data
|
||||||
$fh = tmpfile();
|
if ($this->_tmp_dir === '') {
|
||||||
if ($fh) {
|
$fh = tmpfile();
|
||||||
// Store filehandle
|
|
||||||
$this->_filehandle = $fh;
|
|
||||||
} else {
|
} else {
|
||||||
|
// For people with open base dir restriction
|
||||||
|
$tmpfilename = tempnam($this->_tmp_dir, "Spreadsheet_Excel_Writer");
|
||||||
|
$fh = @fopen($tmpfilename, "w+b");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fh === false) {
|
||||||
// If tmpfile() fails store data in memory
|
// If tmpfile() fails store data in memory
|
||||||
$this->_using_tmpfile = false;
|
$this->_using_tmpfile = false;
|
||||||
|
} else {
|
||||||
|
// Store filehandle
|
||||||
|
$this->_filehandle = $fh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the temp dir used for storing the Excel file
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $dir The dir to be used as temp dir
|
||||||
|
* @return true if given dir is valid, false otherwise
|
||||||
|
*/
|
||||||
|
function setTempDir($dir)
|
||||||
|
{
|
||||||
|
if (is_dir($dir)) {
|
||||||
|
$this->_tmp_dir = $dir;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add data to the beginning of the workbook (note the reverse order)
|
* Add data to the beginning of the workbook (note the reverse order)
|
||||||
* and to the end of the workbook.
|
* and to the end of the workbook.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue