~ubuntu-branches/ubuntu/lucid/phpmyadmin/lucid

« back to all changes in this revision

Viewing changes to libraries/PHPExcel/PHPExcel/Shared/File.php

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-03-08 15:25:00 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100308152500-6e8hmuqc5co39de5
Tags: 4:3.3.0-1
* New upstream version.
* Rediff debian/patches.
* Fix permissions on mediawiki export extension.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * PHPExcel
 
4
 *
 
5
 * Copyright (c) 2006 - 2009 PHPExcel
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2.1 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 *
 
21
 * @category   PHPExcel
 
22
 * @package    PHPExcel_Shared
 
23
 * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
 
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 
25
 * @version    1.7.0, 2009-08-10
 
26
 */
 
27
 
 
28
 
 
29
/**
 
30
 * PHPExcel_Shared_File
 
31
 *
 
32
 * @category   PHPExcel
 
33
 * @package    PHPExcel_Shared
 
34
 * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
 
35
 */
 
36
class PHPExcel_Shared_File
 
37
{
 
38
        /**
 
39
          * Verify if a file exists
 
40
          *
 
41
          * @param      string  $pFilename      Filename
 
42
          * @return bool
 
43
          */
 
44
        public static function file_exists($pFilename) {
 
45
                // Sick construction, but it seems that
 
46
                // file_exists returns strange values when
 
47
                // doing the original file_exists on ZIP archives...
 
48
                if ( strtolower(substr($pFilename, 0, 3)) == 'zip' ) {
 
49
                        // Open ZIP file and verify if the file exists
 
50
                        $zipFile                = substr($pFilename, 6, strpos($pFilename, '#') - 6);
 
51
                        $archiveFile    = substr($pFilename, strpos($pFilename, '#') + 1);
 
52
 
 
53
                        $zip = new ZipArchive();
 
54
                        if ($zip->open($zipFile) === true) {
 
55
                                $returnValue = ($zip->getFromName($archiveFile) !== false);
 
56
                                $zip->close();
 
57
                                return $returnValue;
 
58
                        } else {
 
59
                                return false;
 
60
                        }
 
61
                } else {
 
62
                        // Regular file_exists
 
63
                        return file_exists($pFilename);
 
64
                }
 
65
        }
 
66
 
 
67
        /**
 
68
         * Returns canonicalized absolute pathname, also for ZIP archives
 
69
         *
 
70
         * @param string $pFilename
 
71
         * @return string
 
72
         */
 
73
        public static function realpath($pFilename) {
 
74
                // Returnvalue
 
75
                $returnValue = '';
 
76
 
 
77
                // Try using realpath()
 
78
                $returnValue = realpath($pFilename);
 
79
 
 
80
                // Found something?
 
81
                if ($returnValue == '' || is_null($returnValue)) {
 
82
                        $pathArray = split('/' , $pFilename);
 
83
                        while(in_array('..', $pathArray) && $pathArray[0] != '..') {
 
84
                                for ($i = 0; $i < count($pathArray); ++$i) {
 
85
                                        if ($pathArray[$i] == '..' && $i > 0) {
 
86
                                                unset($pathArray[$i]);
 
87
                                                unset($pathArray[$i - 1]);
 
88
                                                break;
 
89
                                        }
 
90
                                }
 
91
                        }
 
92
                        $returnValue = implode('/', $pathArray);
 
93
                }
 
94
 
 
95
                // Return
 
96
                return $returnValue;
 
97
        }
 
98
}