Beispiel #1
0
 public static function filesize64($file)
 {
     static $iswin;
     if (!isset($iswin)) {
         $iswin = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
     }
     static $exec_works;
     if (!isset($exec_works)) {
         $exec_works = function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') == 'EXEC';
     }
     // try a shell command
     if ($exec_works) {
         $cmd = $iswin ? "for %F in (\"{$file}\") do @echo %~zF" : "stat -c%s \"{$file}\"";
         @exec($cmd, $output);
         if (is_array($output) && ctype_digit($size = trim(implode("\n", $output)))) {
             return intval($size);
         }
     }
     // try the Windows COM interface
     if ($iswin && class_exists("COM")) {
         try {
             $fsobj = new COM('Scripting.FileSystemObject');
             $f = $fsobj->GetFile(realpath($file));
             $size = $f->Size;
         } catch (Exception $e) {
             $size = null;
         }
         if (ctype_digit($size)) {
             return intval($size);
         }
     }
     // if all else fails
     return filesize($file);
 }
function getSize($file)
{
    $size = filesize($file);
    if ($size < 0) {
        if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) {
            $size = trim(`stat -c%s {$file}`);
        } else {
            $fsobj = new COM("Scripting.FileSystemObject");
            $f = $fsobj->GetFile($file);
            $size = $file->Size;
        }
    }
    if ($size > 1000000000) {
        $size = number_format($size / 1000000000, 2, '.', '');
        $size = $size . " GB";
    } else {
        if ($size > 1000000) {
            $size = number_format($size / 1000000, 2, '.', '');
            $size = $size . " MB";
        } else {
            if ($size > 4000) {
                $size = number_format($size / 1000, 2, '.', '');
                $size = $size . " kb";
            } else {
                $size = $size . " bytes";
            }
        }
    }
    return $size;
}
 public function getFileSize($filePath)
 {
     if (!file_exists($filePath)) {
         throw new Exception("source file (" . $filePath . ")is not exist");
     }
     $fs = new COM("Scripting.FileSystemObject");
     $size = $fs->GetFile($filePath)->Size;
     return $size;
 }
 /**
  * Returns file size by using Windows COM interface
  * @inheritdoc
  * @link http://stackoverflow.com/questions/5501451/php-x86-how-to-get-filesize-of-2gb-file-without-external-program/5502328#5502328
  */
 public function getFileSize($path)
 {
     // Use the Windows COM interface
     $fsobj = new \COM('Scripting.FileSystemObject');
     if (dirname($path) == '.') {
         $this->path = substr(getcwd(), -1) == DIRECTORY_SEPARATOR ? getcwd() . basename($path) : getcwd() . DIRECTORY_SEPARATOR . basename($path);
     }
     $f = $fsobj->GetFile($path);
     return BigInteger::of($f->Size);
 }
 /**
  * Return the filesize of the file
  * handle big files (filesize() doesn't)
  * @see http://us3.php.net/manual/fr/function.filesize.php#80959
  * 
  * @param string $file Path to the file
  *
  * @return int the size of the file $file
  */
 public static function getSize($file)
 {
     if (DIRECTORY_SEPARATOR === '/') {
         $filename = escapeshellarg($file);
         $size = trim(`stat -c%s {$filename}`);
     } else {
         $fsobj = new COM("Scripting.FileSystemObject");
         $f = $fsobj->GetFile($file);
         $size = $file->Size;
     }
     return $size;
 }
 /**
  * Return the filesize of the file
  * handle big files (filesize() doesn't)
  * @see http://us3.php.net/manual/fr/function.filesize.php#80959
  * 
  * @param string $file Path to the file
  *
  * @return int the size of the file $file
  */
 public static function getSize($file)
 {
     $size = @filesize($file);
     if ($size === false) {
         if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) {
             $size = trim(`stat -c%s {$file}`);
         } else {
             $fsobj = new COM("Scripting.FileSystemObject");
             $f = $fsobj->GetFile($file);
             $size = $file->Size;
         }
     }
     return $size;
 }
Beispiel #7
0
function fileSize64($file)
{
    //Le système d'exploitation est-il un windows?
    static $isWindows;
    if (!isset($isWindows)) {
        $isWindows = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
    }
    //La commande exec est-elle disponible?
    static $execWorks;
    if (!isset($execWorks)) {
        $execWorks = function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') == 'EXEC';
    }
    //Essaye une commande shell
    if ($execWorks) {
        $cmd = $isWindows ? "for %F in (\"{$file}\") do @echo %~zF" : "stat -c%s \"{$file}\"";
        @exec($cmd, $output);
        /*
         * ctype_digit vérifie si tous les caractères de la chaîne sont des chiffres
         * @link https://php.net/manual/fr/function.ctype-digit.php
         */
        if (is_array($output) && ctype_digit($size = trim(implode("\n", $output)))) {
            return round($size / 1024, 0);
        }
        //conversion en Kb
    }
    //Essaye l'interface Windows COM
    if ($isWindows && class_exists("COM")) {
        try {
            //@link https://php.net/manual/fr/class.com.php
            $fileSystemObject = new COM('Scripting.FileSystemObject');
            //accès au système de fichier de l'ordinateur
            //retourne un objet fichier
            $fileObject = $fileSystemObject->GetFile(realpath($file));
            //retourne la taille du fichier en octets
            $size = $fileObject->Size;
        } catch (Exception $e) {
            $size = null;
        }
        if (ctype_digit($size)) {
            return round($size / 1024, 0);
        }
        //conversion en Kb
    }
    //En dernier recours utilise filesize (qui ne fonctionne pas correctement pour des fichiers de plus de 2 Go.
    return round(filesize($file) / 1024, 0);
}
Beispiel #8
0
function file_utils_get_size($file)
{
    //Uncomment when limitation is fixed
    //return filesize($file);
    if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) {
        //if filename containing spaces
        $filename = escapeshellarg($file);
        $size = trim(`stat -c%s {$filename}`);
        //$size = filesize($file);
    } else {
        // Not tested...
        $fsobj = new COM("Scripting.FileSystemObject");
        $f = $fsobj->GetFile($file);
        $size = $file->Size;
    }
    return $size;
}
 function true_filesize($file, $f = false)
 {
     global $config;
     static $cache;
     static $fsobj = false;
     if (isset($cache[$file])) {
         return $cache[$file];
     }
     if (is_dir($file)) {
         return 0;
     }
     if (PHP_INT_SIZE > 4 || @$config['disable_4gb_support']) {
         $size = filesize($file);
     } else {
         if (OS_ISWINDOWS) {
             if (class_exists("COM")) {
                 if ($fsobj === FALSE) {
                     $fsobj = new COM("Scripting.FileSystemObject");
                 }
                 $ofile = $fsobj->GetFile($file);
                 $size = $ofile->Size + 1 - 1;
                 $cache[$file] = $size;
             } else {
                 $size = filesize($file);
             }
         } else {
             $dir = dirname($file);
             $list = array();
             exec("ls -l " . escapeshellarg($dir) . '/', $list);
             $files = $this->ParseUnixList($list, @$config['ls_dateformat_in_iso8601']);
             foreach ($files as $v) {
                 $cache[$dir . "/" . $v['name']] = $v['size'];
             }
             if (isset($config['follow_symlink']) && $config['follow_symlink']) {
                 foreach ($files as $v) {
                     if ($v['is_link']) {
                         $cache[$dir . "/" . $v['name']] = $this->true_filesize($v['link'], true);
                     }
                 }
             }
             $size = $cache[$file];
         }
     }
     return $size;
 }
Beispiel #10
0
 /**
  * Get the size of a file
  * Works for large files too (>2GB)
  * @param string $path File's path
  * @param double File's size
  */
 public static function getFileSize(string $path)
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         if (class_exists('COM')) {
             $fsobj = new COM('Scripting.FileSystemObject');
             $f = $fsobj->GetFile(realpath($path));
             $size = $f->Size;
         } else {
             $size = trim(exec("for %F in (\"" . $path . "\") do @echo %~zF"));
         }
     } elseif (PHP_OS == 'Darwin') {
         $size = trim(shell_exec("stat -f %z " . escapeshellarg($path)));
     } elseif (in_array(PHP_OS, ['Linux', 'FreeBSD', 'Unix', 'SunOS'])) {
         $size = trim(shell_exec("stat -c%s " . escapeshellarg($path)));
     } else {
         $size = filesize($path);
     }
     return doubleval($size);
 }
Beispiel #11
0
 private static function relocateShortcut()
 {
     $WshShell = new COM('WScript.Shell', null, CP_UTF8);
     $FSO = new COM('Scripting.FileSystemObject', null, CP_UTF8);
     $desktop = $WshShell->SpecialFolders('Desktop');
     $startmenu = $WshShell->SpecialFolders('Programs');
     $startmenu = $FSO->BuildPath($startmenu, utf8_encode('XAMPP for Windows'));
     $xampppath = utf8_encode(self::$xampppath);
     $links = array();
     $links[$FSO->BuildPath($desktop, utf8_encode('XAMPP Control Panel.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'Description' => utf8_encode('XAMPP Control Panel'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Control Panel.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp-control.exe')), 'Description' => utf8_encode('XAMPP Control Panel'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Setup.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp_setup.bat')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp_cli.exe')), 'Description' => utf8_encode('XAMPP Setup'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Shell.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('xampp_shell.bat')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp_cli.exe')), 'Description' => utf8_encode('XAMPP Shell'));
     $links[$FSO->BuildPath($startmenu, utf8_encode('XAMPP Uninstall.lnk'))] = array('TargetPath' => $FSO->BuildPath($xampppath, utf8_encode('uninstall_xampp.bat')), 'WorkingDirectory' => $xampppath, 'WindowStyle' => 1, 'IconLocation' => $FSO->BuildPath($xampppath, utf8_encode('xampp_cli.exe')), 'Description' => utf8_encode('XAMPP Uninstall'));
     foreach ($links as $shortcut => $value) {
         if (!$FSO->FileExists($shortcut)) {
             continue;
         }
         try {
             $shortcut_file = $FSO->GetFile($shortcut);
             $oldfileperm = $shortcut_file->attributes;
             if (($oldfileperm & 1) == 1) {
                 $shortcut_file->attributes += -1;
             }
         } catch (Exception $e) {
             throw new XAMPPException('File \'' . utf8_decode($shortcut) . '\' is not writable.');
         }
         $ShellLink = $WshShell->CreateShortcut($shortcut);
         $ShellLink->TargetPath = $value['TargetPath'];
         $ShellLink->WorkingDirectory = $value['WorkingDirectory'];
         $ShellLink->WindowStyle = $value['WindowStyle'];
         $ShellLink->IconLocation = $value['IconLocation'];
         $ShellLink->Description = $value['Description'];
         $ShellLink->Save();
         $ShellLink = null;
         $shortcut_file->attributes = $oldfileperm;
         $shortcut_file = null;
     }
     $FSO = null;
     $WshShell = null;
     return;
 }
Beispiel #12
0
 /**
  * get file size
  *
  * @access public
  * @param  string  $file
  * @param  boolean $convert - call byte_convert(); default: false
  * @return string
  **/
 public static function getSize($file, $convert = false)
 {
     $file = self::sanitizePath($file);
     if (is_dir($file)) {
         return false;
     }
     if (!file_exists($file)) {
         return false;
     }
     $size = @filesize($file);
     if ($size < 0) {
         if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) {
             $size = trim(`stat -c%s {$file}`);
         } else {
             if (extension_loaded('COM')) {
                 $fsobj = new COM("Scripting.FileSystemObject");
                 $f = $fsobj->GetFile($file);
                 $size = $file->Size;
             }
         }
     }
     if ($size && $convert) {
         $size = self::byte_convert($size);
     }
     return $size;
 }
 function getTrueSize($file)
 {
     if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) {
         $cmd = "stat -L -c%s \"" . $file . "\"";
         $val = trim(`{$cmd}`);
         if (strlen($val) == 0 || floatval($val) == 0) {
             // No stat on system
             $cmd = "ls -1s --block-size=1 \"" . $file . "\"";
             $val = trim(`{$cmd}`);
         }
         if (strlen($val) == 0 || floatval($val) == 0) {
             // No block-size on system (probably busybox), try long output
             $cmd = "ls -l \"" . $file . "\"";
             $arr = explode("/[\\s]+/", `{$cmd}`);
             $val = trim($arr[4]);
         }
         if (strlen($val) == 0 || floatval($val) == 0) {
             // Still not working, get a value at least, not 0...
             $val = sprintf("%u", filesize($file));
         }
         return floatval($val);
     } else {
         if (class_exists("COM")) {
             $fsobj = new COM("Scripting.FileSystemObject");
             $f = $fsobj->GetFile($file);
             return floatval($f->Size);
         } else {
             if (is_file($file)) {
                 return exec('FOR %A IN ("' . $file . '") DO @ECHO %~zA');
             } else {
                 return sprintf("%u", filesize($file));
             }
         }
     }
 }
Beispiel #14
0
/**
 * Since filesize() was giving trouble with files larger
 * than 2gb, I looked for a solution and found this great
 * function by Alessandro Marinuzzi from www.alecos.it on
 * http://stackoverflow.com/questions/5501451/php-x86-how-
 * to-get-filesize-of-2gb-file-without-external-program
 *
 * I changed the name of the function and split it in 2,
 * because I do not want to display it directly.
 */
function get_real_size($file)
{
    clearstatcache();
    if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
        if (class_exists("COM")) {
            $fsobj = new COM('Scripting.FileSystemObject');
            $f = $fsobj->GetFile(realpath($file));
            $ff = $f->Size;
        } else {
            $ff = trim(exec("for %F in (\"" . $file . "\") do @echo %~zF"));
        }
    } elseif (PHP_OS == 'Darwin') {
        $ff = trim(shell_exec("stat -f %z " . escapeshellarg($file)));
    } elseif (PHP_OS == 'Linux' || PHP_OS == 'FreeBSD' || PHP_OS == 'Unix' || PHP_OS == 'SunOS') {
        $ff = trim(shell_exec("stat -c%s " . escapeshellarg($file)));
    } else {
        $ff = filesize($file);
    }
    /** Fix for 0kb downloads by AlanReiblein */
    if (!ctype_digit($ff)) {
        /* returned value not a number so try filesize() */
        $ff = filesize($file);
    }
    return $ff;
}
Beispiel #15
0
 /**
  * Get size in bytes of the file. This also supports files over 2GB in Windows,
  * which is not supported by PHP's filesize().
  *
  * @param string $path path of the file to check
  * @return int
  */
 public static function fileSize($path)
 {
     if (strpos(strtolower(PHP_OS), 'win') === 0) {
         $filesystem = new COM('Scripting.FileSystemObject');
         $file = $filesystem->GetFile($path);
         return $file->Size();
     } else {
         return filesize($path);
     }
 }
Beispiel #16
0
 /**
  * return file size in bytes
  *
  * @return      int                 filesize in bytes or -1 if it fails
  */
 public function getSize()
 {
     $filePath = $this->getPathname();
     $size = -1;
     $isWin = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
     $execWorks = function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') == 'EXEC';
     if ($isWin) {
         if ($execWorks) {
             $cmd = "for %F in (\"{$filePath}\") do @echo %~zF";
             @exec($cmd, $output);
             if (is_array($output)) {
                 $result = trim(implode("\n", $output));
                 if (ctype_digit($result)) {
                     $size = $result;
                 }
             }
         }
         // try the Windows COM interface if its fails
         if (class_exists('COM') && $size > -1) {
             $fsobj = new COM('Scripting.FileSystemObject');
             $file = $fsobj->GetFile($filePath);
             $result = $file->Size;
             if (ctype_digit($result)) {
                 $size = $result;
             }
         }
     } else {
         $result = trim("stat -c%s {$filePath}");
         if (ctype_digit($result)) {
             $size = $result;
         }
     }
     if ($size < 0) {
         $size = filesize($filePath);
     }
     return $size;
 }
Beispiel #17
0
function getSize($file)
{
    $size = filesize($file);
    if ($size < 0) {
        if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
            $size = @escapeshellarg($file);
            $size = trim(`stat -c%s {$file}`);
        } else {
            $fsobj = new COM('Scripting.FileSystemObject');
            $f = $fsobj->GetFile($file);
            $size = $file->Size;
        }
    }
    return $size;
}
Beispiel #18
0
 /**
  * 
  * @copyright Thanks to "Unsigned", posted on stackoverflow, 
  * from BSD-licensed SoloAdmin
  * @param string $path
  * @return int|string Gets the file size in bytes as string or integer
  */
 static function GetSize($path)
 {
     // If the platform is Windows...
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         // Try using the NT substition modifier %~z
         $size = trim(exec("for %F in (\"" . $path . "\") do @echo %~zF"));
         // If the return is blank, zero, or not a number
         if (!$size || !ctype_digit($size)) {
             // Use the Windows COM interface
             $fsobj = new COM('Scripting.FileSystemObject');
             if (dirname($path) == '.') {
                 $path = Path::Combine(getcwd(), Path::Filename($path));
             }
             $f = $fsobj->GetFile($path);
             return $f->Size;
         }
         // Otherwise, return the result of the 'for' command
         return $size;
     }
     // If the platform is not Windows, use the stat command (should work for *nix and MacOS)
     return trim(exec("stat -c%s {$path}"));
 }
Beispiel #19
0
 /**
  * @brief Tries to get the size of a file via the Windows DOM extension.
  *
  * @param string $filename Path to the file.
  *
  * @return null|int|float Number of bytes as number (float or int) or
  *                        null on failure.
  */
 public function getFileSizeViaCOM($filename)
 {
     if (class_exists('COM')) {
         $fsObj = new \COM("Scripting.FileSystemObject");
         $file = $fsObj->GetFile($filename);
         return 0 + $file->Size;
     }
     return null;
 }
Beispiel #20
0
function filesize_unlimited($path)
    {
    # A resolution for PHP's issue with large files and filesize().

    if (PHP_OS=='WINNT')
        {
	if (class_exists("COM"))
		{
		$filesystem=new COM('Scripting.FileSystemObject');
		$file=$filesystem->GetFile($path);
		return $file->Size();
		}
	else
		{
		return exec('for %I in (' . escapeshellarg($path) . ') do @echo %~zI' );
		}
        }
    else
        {
        # Attempt to use 'du' utility.
        $f2 = exec("du -k " . escapeshellarg($path));
        $f2s = explode("\t",$f2);
        if (count($f2s)!=2) {return @filesize($path);} # Bomb out, the output wasn't as we expected. Return the filesize() output.
        return $f2s[0] * 1024;
        }
    }
 private static function getFileSizeFromOS($fullPath)
 {
     $name = strtolower(php_uname('s'));
     // Windows OS: we use COM to access the filesystem
     if (strpos($name, 'win') !== false) {
         if (class_exists('COM')) {
             $fsobj = new \COM("Scripting.FileSystemObject");
             $f = $fsobj->GetFile($fullPath);
             return $f->Size;
         }
     } else {
         if (strpos($name, 'bsd') !== false) {
             if (\OC_Helper::is_function_enabled('exec')) {
                 return (double) exec('stat -f %z ' . escapeshellarg($fullPath));
             }
         } else {
             if (strpos($name, 'linux') !== false) {
                 if (\OC_Helper::is_function_enabled('exec')) {
                     return (double) exec('stat -c %s ' . escapeshellarg($fullPath));
                 }
             } else {
                 \OC_Log::write('core', 'Unable to determine file size of "' . $fullPath . '". Unknown OS: ' . $name, \OC_Log::ERROR);
             }
         }
     }
     return 0;
 }
Beispiel #22
0
function GetDatabaseMetaData($name)
{
    global $db;
    $fsize = -1;
    $query = "select FILENAME from MASTER.DBO.SYSDATABASES where NAME=\"{$name}\"";
    $result = sqlsrv_query($db, $query);
    do {
        while ($row = sqlsrv_fetch_array($result)) {
            $fname = $row[0];
            if (file_exists($fname)) {
                $fsobj = new COM("Scripting.FileSystemObject");
                $data = $fsobj->GetFile($fname);
                $fsize = $data->Size + 1 - 1;
                $data = 0;
            }
        }
    } while (sqlsrv_next_result($result));
    sqlsrv_free_stmt($result);
    return array($fname, $fsize);
}
Beispiel #23
0
 /**
  * Returns file size by using Windows COM interface
  *
  * @see http://stackoverflow.com/questions/5501451/php-x86-how-to-get-filesize-of-2gb-file-without-external-program/5502328#5502328
  *
  * @return string | boolean
  */
 private function sizeCom()
 {
     if (class_exists("COM")) {
         // Use the Windows COM interface
         $fsobj = new \COM("Scripting.FileSystemObject");
         $path = $this->path;
         if (dirname($path) == ".") {
             $path = substr(getcwd(), -1) == DIRECTORY_SEPARATOR ? getcwd() . basename($this->path) : getcwd() . DIRECTORY_SEPARATOR . basename($this->path);
         }
         $f = $fsobj->GetFile($path);
         return (string) $f->Size;
     }
 }
Beispiel #24
0
 public function openfile($filename)
 {
     try {
         if (!empty($this->startup_error)) {
             throw new getid3_exception($this->startup_error);
         }
         if (!empty($this->startup_warning)) {
             $this->warning($this->startup_warning);
         }
         // init result array and set parameters
         $this->filename = $filename;
         $this->info = array();
         $this->info['GETID3_VERSION'] = $this->version();
         $this->info['php_memory_limit'] = $this->memory_limit;
         // remote files not supported
         if (preg_match('/^(ht|f)tp:\\/\\//', $filename)) {
             throw new getid3_exception('Remote files are not supported - please copy the file locally first');
         }
         $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
         $filename = preg_replace('#(.+)' . preg_quote(DIRECTORY_SEPARATOR) . '{2,}#U', '\\1' . DIRECTORY_SEPARATOR, $filename);
         // open local file
         if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
             // great
         } else {
             throw new getid3_exception('Could not open "' . $filename . '" (does not exist, or is not a file)');
         }
         $this->info['filesize'] = filesize($filename);
         // set redundant parameters - might be needed in some include file
         $this->info['filename'] = basename($filename);
         $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
         $this->info['filenamepath'] = $this->info['filepath'] . '/' . $this->info['filename'];
         // option_max_2gb_check
         if ($this->option_max_2gb_check) {
             // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
             // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
             // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
             $fseek = fseek($this->fp, 0, SEEK_END);
             if ($fseek < 0 || $this->info['filesize'] != 0 && ftell($this->fp) == 0 || $this->info['filesize'] < 0 || ftell($this->fp) < 0) {
                 $real_filesize = false;
                 if (GETID3_OS_ISWINDOWS) {
                     if (class_exists('COM')) {
                         $filesystem = new COM('Scripting.FileSystemObject');
                         $file = $filesystem->GetFile($this->info['filenamepath']);
                         $real_filesize = $file->Size();
                         unset($filesystem, $file);
                     } else {
                         // From PHP 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini:
                         $this->warning('COM class not available.' . (version_compare(PHP_VERSION, '5.4.5', '>=') ? ' COM and DOTNET support are no longer built into PHP since v5.4.5, please enable in php.ini' : ''));
                         $commandline = 'dir /-C "' . str_replace('/', DIRECTORY_SEPARATOR, $filename) . '"';
                         $dir_output = `{$commandline}`;
                         if (preg_match('#1 File\\(s\\)[ ]+([0-9]+) bytes#i', $dir_output, $matches)) {
                             $real_filesize = (double) $matches[1];
                         }
                     }
                 } else {
                     $commandline = 'ls -o -g -G --time-style=long-iso ' . escapeshellarg($this->info['filenamepath']);
                     $dir_output = `{$commandline}`;
                     if (preg_match('#([0-9]+) ([0-9]{4}-[0-9]{2}\\-[0-9]{2} [0-9]{2}:[0-9]{2}) ' . str_replace('#', '\\#', preg_quote($filename)) . '$#', $dir_output, $matches)) {
                         $real_filesize = (double) $matches[1];
                     }
                 }
                 if ($real_filesize === false) {
                     unset($this->info['filesize']);
                     fclose($this->fp);
                     throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB and is not supported by PHP.');
                 } elseif (getid3_lib::intValueSupported($real_filesize)) {
                     unset($this->info['filesize']);
                     fclose($this->fp);
                     throw new getid3_exception('PHP seems to think the file is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB, but filesystem reports it as ' . number_format($real_filesize, 3) . 'GB, please report to info@getid3.org');
                 }
                 $this->info['filesize'] = $real_filesize;
                 $this->error('File is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB (filesystem reports it as ' . number_format($real_filesize, 3) . 'GB) and is not properly supported by PHP.');
             }
         }
         // set more parameters
         $this->info['avdataoffset'] = 0;
         $this->info['avdataend'] = $this->info['filesize'];
         $this->info['fileformat'] = '';
         // filled in later
         $this->info['audio']['dataformat'] = '';
         // filled in later, unset if not used
         $this->info['video']['dataformat'] = '';
         // filled in later, unset if not used
         $this->info['tags'] = array();
         // filled in later, unset if not used
         $this->info['error'] = array();
         // filled in later, unset if not used
         $this->info['warning'] = array();
         // filled in later, unset if not used
         $this->info['comments'] = array();
         // filled in later, unset if not used
         $this->info['encoding'] = $this->encoding;
         // required by id3v2 and iso modules - can be unset at the end if desired
         return true;
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
     return false;
 }
Beispiel #25
0
function filesize_unlimited($path)
{
    # A resolution for PHP's issue with large files and filesize().
    if (PHP_OS == 'WINNT') {
        if (class_exists("COM")) {
            try {
                $filesystem = new COM('Scripting.FileSystemObject');
                $file = $filesystem->GetFile($path);
                return $file->Size();
            } catch (com_exception $e) {
                return false;
            }
        }
        return exec('for %I in (' . escapeshellarg($path) . ') do @echo %~zI');
    } else {
        if (PHP_OS == 'Darwin') {
            $bytesize = exec("stat -f '%z' " . escapeshellarg($path));
        } else {
            $bytesize = exec("stat -c '%s' " . escapeshellarg($path));
        }
    }
    if (!is_int($bytesize)) {
        return @filesize($path);
        # Bomb out, the output wasn't as we expected. Return the filesize() output.
    }
    return $bytesize;
}
 /**
  * Determine size of specified file
  * Applicable for all files, also those files what have size > 4 GB at Windows
  *
  * @param $file
  * @link http://www.php.net/manual/en/function.filesize.php#104101
  *
  * @return float
  */
 protected function _getFileSize($file)
 {
     if (class_exists('COM', false) && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         try {
             $filesystem = new COM('Scripting.FileSystemObject');
             $file = $filesystem->GetFile(realpath($file));
             $size = $file->Size();
             if (!ctype_digit($size)) {
                 return null;
             }
         } catch (Exception $e) {
             $size = null;
         }
     } else {
         $size = filesize($file);
     }
     if ($size < 0 || $size === false) {
         return null;
     }
     return $size;
 }
 public function filesize($fileUrl)
 {
     if (self::is_dir($fileUrl)) {
         return 0;
     }
     if (PHP_INT_SIZE > 4 || @Lms_Ufs::$config['disable_4gb_support']) {
         //Для систем с битностью больше 32 размер файла больше 4 Гб определяется корректно
         return filesize(self::urlToPath($fileUrl));
     }
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         if (class_exists("COM")) {
             $fsobj = new COM("Scripting.FileSystemObject");
             $ofile = $fsobj->GetFile(self::urlToPath($fileUrl));
             $size = floatval($ofile->Size);
         } else {
             throw new Exception("There is no COM Object. Can't get real filesize for files more than 4 Gb");
             //$size = filesize(self::urlToPath($fileUrl));
         }
     } else {
         $file = self::urlToPath($fileUrl);
         $dir = dirname($file);
         $list = array();
         if (function_exists('exec')) {
             exec("ls -l " . escapeshellarg($dir) . '/', $list);
             $files = self::_ParseUnixList($list, @Lms_Ufs::$config['ls_dateformat_in_iso8601']);
             foreach ($files as $v) {
                 $cache[$dir . "/" . $v['name']] = $v['size'];
             }
             $size = $cache[$file];
         } else {
             throw new Exception("Can't perform shell command. Probably 'exec' is disabled in your php.ini file");
         }
     }
     return $size;
 }
Beispiel #28
0
 public static function getFileSize($path)
 {
     $success = FALSE;
     $isresource = FALSE;
     if (!is_resource($path)) {
         $isresource = FALSE;
         $resource = fopen($path, "r");
     } else {
         $isresource = TRUE;
         $resource = $path;
     }
     $stat = fstat($resource);
     $size = $stat["size"];
     if ($size < 0) {
         $success = FALSE;
     } else {
         $success = TRUE;
     }
     if ($success) {
         return $size;
     } else {
         if ($isresource) {
             throw new Ks3ClientException("please use file path instead resource");
         }
     }
     if (!(strtoupper(substr(PHP_OS, 0, 3)) == "WIN")) {
         //如果不是windows系统,尝试使用stat命令
         $size = trim(`stat -c%s {$path}`);
     } else {
         //如果是windows系统,尝试cmd命令
         if (!class_exists("COM")) {
             throw new Ks3ClientException("please add 'extension=php_com_dotnet.dll' and set 'com.allow_dcom = true' in php.ini and restart");
         }
         $fs = new COM("Scripting.FileSystemObject");
         $size = $fs->GetFile($path)->Size;
     }
     return $size;
 }
 public static function getFileSizeSyscall($path)
 {
     $filesize = false;
     if (GETID3_OS_ISWINDOWS) {
         if (class_exists('COM')) {
             // From PHP 5.3.15 and 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini:
             $filesystem = new COM('Scripting.FileSystemObject');
             $file = $filesystem->GetFile($path);
             $filesize = $file->Size();
             unset($filesystem, $file);
         } else {
             $commandline = 'for %I in (' . escapeshellarg($path) . ') do @echo %~zI';
         }
     } else {
         $commandline = 'ls -l ' . escapeshellarg($path) . ' | awk \'{print $5}\'';
     }
     if (isset($commandline)) {
         $output = trim(`{$commandline}`);
         if (ctype_digit($output)) {
             $filesize = (double) $output;
         }
     }
     return $filesize;
 }
Beispiel #30
0
 /**
  * Calculates the size of the given file.
  *
  * This is fiddly on 32-bit systems for sizes larger than 2GB due to internal
  * limitations - filesize() returns a signed long - and so needs hackery.
  *
  * @param   string   $file  full path to the file
  * @return  integer|float   the file size in bytes
  */
 public static function getFileSize($file)
 {
     // 64-bit systems should be OK
     if (PHP_INT_SIZE > 4) {
         return filesize($file);
     }
     // Hack for Windows
     if (DIRECTORY_SEPARATOR === '\\') {
         if (!extension_loaded('com_dotnet')) {
             return trim(shell_exec('for %f in (' . escapeshellarg($file) . ') do @echo %~zf')) + 0;
         }
         $com = new COM('Scripting.FileSystemObject');
         $f = $com->GetFile($file);
         return $f->Size + 0;
     }
     // Hack for *nix
     $os = php_uname();
     if (stripos($os, 'Darwin') !== false) {
         $command = 'stat -f %z ' . escapeshellarg($file);
     } elseif (stripos($os, 'DiskStation') !== false) {
         $command = 'ls -l ' . escapeshellarg($file) . ' | awk \'{print $5}\'';
     } else {
         $command = 'stat -c %s ' . escapeshellarg($file);
     }
     return trim(shell_exec($command)) + 0;
 }