/** * If we are on a server with open_basedir, we must move the file * before opening it. The FAQ 1.11 explains how to create the "./tmp" * directory - if needed * * @todo move check of $cfg['TempDir'] into Config? * @access public * @return boolean whether uploaded file is fine or not */ public function checkUploadedFile() { if ($this->isReadable()) { return true; } $tmp_subdir = ConfigFile::getDefaultTempDirectory(); if (@is_writable($tmp_subdir)) { // cannot create directory or access, point user to FAQ 1.11 $this->_error_message = Message::error(__('Error moving the uploaded file, see [doc@faq1-11]FAQ 1.11[/doc].')); return false; } $new_file_to_upload = tempnam(realpath($tmp_subdir), basename($this->getName())); // suppress warnings from being displayed, but not from being logged // any file access outside of open_basedir will issue a warning ob_start(); $move_uploaded_file_result = move_uploaded_file($this->getName(), $new_file_to_upload); ob_end_clean(); if (!$move_uploaded_file_result) { $this->_error_message = Message::error(__('Error while moving uploaded file.')); return false; } $this->setName($new_file_to_upload); $this->isTemp(true); if (!$this->isReadable()) { $this->_error_message = Message::error(__('Cannot read uploaded file.')); return false; } return true; }
/** * Kanji file encoding convert * * @param string $file the name of the file to convert * @param string $enc the destination encoding code * @param string $kana set 'kana' convert to JIS-X208-kana * * @return string the name of the converted file */ public static function kanjiFileConv($file, $enc, $kana) { if ($enc == '' && $kana == '') { return $file; } $tmpfname = tempnam(ConfigFile::getDefaultTempDirectory(), $enc); $fpd = fopen($tmpfname, 'wb'); $fps = fopen($file, 'r'); self::kanjiChangeOrder(); while (!feof($fps)) { $line = fgets($fps, 4096); $dist = self::kanjiStrConv($line, $enc, $kana); fputs($fpd, $dist); } // end while self::kanjiChangeOrder(); fclose($fps); fclose($fpd); unlink($file); return $tmpfname; }