PMA\libraries\File::open PHP Method

open() public method

Attempts to open the file.
public open ( ) : boolean
return boolean
    public function open()
    {
        if (!$this->_decompress) {
            $this->_handle = @fopen($this->getName(), 'r');
        }
        switch ($this->getCompression()) {
            case false:
                return false;
            case 'application/bzip2':
                if ($GLOBALS['cfg']['BZipDump'] && @function_exists('bzopen')) {
                    $this->_handle = @bzopen($this->getName(), 'r');
                } else {
                    $this->errorUnsupported();
                    return false;
                }
                break;
            case 'application/gzip':
                if ($GLOBALS['cfg']['GZipDump'] && @function_exists('gzopen')) {
                    $this->_handle = @gzopen($this->getName(), 'r');
                } else {
                    $this->errorUnsupported();
                    return false;
                }
                break;
            case 'application/zip':
                if ($GLOBALS['cfg']['ZipDump'] && @function_exists('zip_open')) {
                    return $this->openZip();
                } else {
                    $this->errorUnsupported();
                    return false;
                }
            case 'none':
                $this->_handle = @fopen($this->getName(), 'r');
                break;
            default:
                $this->errorUnsupported();
                return false;
        }
        return $this->_handle !== false;
    }

Usage Example

Example #1
0
    }
} elseif (empty($import_file) || !is_uploaded_file($import_file)) {
    $import_file = 'none';
}
// Do we have file to import?
if ($import_file != 'none' && !$error) {
    /**
     *  Handle file compression
     */
    $import_handle = new File($import_file);
    $import_handle->checkUploadedFile();
    if ($import_handle->isError()) {
        PMA_stopImport($import_handle->getError());
    }
    $import_handle->setDecompressContent(true);
    $import_handle->open();
    if ($import_handle->isError()) {
        PMA_stopImport($import_handle->getError());
    }
} elseif (!$error) {
    if (!isset($import_text) || empty($import_text)) {
        $message = PMA\libraries\Message::error(__('No data was received to import. Either no file name was ' . 'submitted, or the file size exceeded the maximum size permitted ' . 'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].'));
        PMA_stopImport($message);
    }
}
// so we can obtain the message
//$_SESSION['Import_message'] = $message->getDisplay();
// Convert the file's charset if necessary
if (Encoding::isSupported() && isset($charset_of_file)) {
    if ($charset_of_file != 'utf-8') {
        $charset_conversion = true;