Zend Framework : Could not determine temp directory, please specify a cache_dir manually

后端 未结 8 732
忘了有多久
忘了有多久 2021-01-14 15:44

I am just learning Zend Framework. I created a simple Zend_Form and when I submitted the form I got following error:

An error occurred
Application error
Exce         


        
相关标签:
8条回答
  • 2021-01-14 16:24

    I have created "tmp" folder in the main directory it worked for me

    0 讨论(0)
  • 2021-01-14 16:25

    When looking at the Zend/Cache/Backend.php code, there are some alternatives to allow correct guessing of the cache_dir:

    • Setting evironment variables like TMPDIR, TEMP or TMP
    • set "upload_tmp_dir" in php.ini
    • allow access to "/tmp" or "\temp"

    At least that's how I read the code:

    /**
     * Determine system TMP directory and detect if we have read access
     *
     * inspired from Zend_File_Transfer_Adapter_Abstract
     *
     * @return string
     * @throws Zend_Cache_Exception if unable to determine directory
     */
    public function getTmpDir()
    {
        $tmpdir = array();
        foreach (array($_ENV, $_SERVER) as $tab) {
            foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
                if (isset($tab[$key])) {
                    if (($key == 'windir') or ($key == 'SystemRoot')) {
                        $dir = realpath($tab[$key] . '\\temp');
                    } else {
                        $dir = realpath($tab[$key]);
                    }
                    if ($this->_isGoodTmpDir($dir)) {
                        return $dir;
                    }
                }
            }
        }
        $upload = ini_get('upload_tmp_dir');
        if ($upload) {
            $dir = realpath($upload);
            if ($this->_isGoodTmpDir($dir)) {
                return $dir;
            }
        }
        if (function_exists('sys_get_temp_dir')) {
            $dir = sys_get_temp_dir();
            if ($this->_isGoodTmpDir($dir)) {
                return $dir;
            }
        }
        // Attemp to detect by creating a temporary file
        $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
        if ($tempFile) {
            $dir = realpath(dirname($tempFile));
            unlink($tempFile);
            if ($this->_isGoodTmpDir($dir)) {
                return $dir;
            }
        }
        if ($this->_isGoodTmpDir('/tmp')) {
            return '/tmp';
        }
        if ($this->_isGoodTmpDir('\\temp')) {
            return '\\temp';
        }
        Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
    }
    
    0 讨论(0)
提交回复
热议问题