Файловый менеджер - Редактировать - /var/www/html/fsfile.zip
Ðазад
PK ! �9�_" " FSFile.phpnu �Iw�� <?php /** * Non-directory file on the file system. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file * @ingroup FileBackend */ namespace Wikimedia\FileBackend\FSFile; use Wikimedia\AtEase\AtEase; use Wikimedia\Timestamp\ConvertibleTimestamp; /** * Class representing a non-directory file on the file system * * @ingroup FileBackend */ class FSFile { /** @var string Path to file */ protected $path; /** @var string File SHA-1 in base 36 */ protected $sha1Base36; /** * Sets up the file object * * @param string $path Path to temporary file on local disk */ public function __construct( $path ) { $this->path = $path; } /** * Returns the file system path * * @return string */ public function getPath() { return $this->path; } /** * Checks if the file exists * * @return bool */ public function exists() { return is_file( $this->path ); } /** * Get the file size in bytes * * @return int|bool */ public function getSize() { AtEase::suppressWarnings(); $size = filesize( $this->path ); AtEase::restoreWarnings(); return $size; } /** * Get the file's last-modified timestamp * * @return string|bool TS_MW timestamp or false on failure */ public function getTimestamp() { AtEase::suppressWarnings(); $timestamp = filemtime( $this->path ); AtEase::restoreWarnings(); if ( $timestamp !== false ) { $timestamp = ConvertibleTimestamp::convert( TS_MW, $timestamp ); } return $timestamp; } /** * Get an associative array containing information about * a file with the given storage path. * * Resulting array fields include: * - fileExists * - size (filesize in bytes) * - mime (as major/minor) * - file-mime (as major/minor) * - sha1 (in base 36) * - major_mime * - minor_mime * * @param string|bool $ext The file extension, or true to extract it from the filename. * Set it to false to ignore the extension. Currently unused. * @return array */ public function getProps( $ext = true ) { $info = self::placeholderProps(); $info['fileExists'] = $this->exists(); if ( $info['fileExists'] ) { $info['size'] = $this->getSize(); // bytes $info['sha1'] = $this->getSha1Base36(); $mime = mime_content_type( $this->path ); # MIME type according to file contents $info['file-mime'] = ( $mime === false ) ? 'unknown/unknown' : $mime; # logical MIME type $info['mime'] = $mime; if ( strpos( $mime, '/' ) !== false ) { [ $info['major_mime'], $info['minor_mime'] ] = explode( '/', $mime, 2 ); } else { [ $info['major_mime'], $info['minor_mime'] ] = [ $mime, 'unknown' ]; } } return $info; } /** * Placeholder file properties to use for files that don't exist * * Resulting array fields include: * - fileExists * - size (filesize in bytes) * - mime (as major/minor) * - file-mime (as major/minor) * - sha1 (in base 36) * - major_mime * - minor_mime * * @return array */ public static function placeholderProps() { $info = []; $info['fileExists'] = false; $info['size'] = 0; $info['file-mime'] = null; $info['major_mime'] = null; $info['minor_mime'] = null; $info['mime'] = null; $info['sha1'] = ''; return $info; } /** * Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case * encoding, zero padded to 31 digits. * * 160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36 * fairly neatly. * * @param bool $recache * @return bool|string False on failure */ public function getSha1Base36( $recache = false ) { if ( $this->sha1Base36 !== null && !$recache ) { return $this->sha1Base36; } AtEase::suppressWarnings(); $this->sha1Base36 = sha1_file( $this->path ); AtEase::restoreWarnings(); if ( $this->sha1Base36 !== false ) { $this->sha1Base36 = \Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 ); } return $this->sha1Base36; } /** * Get the final file extension from a file system path * * @param string $path * @return string */ public static function extensionFromPath( $path ) { $i = strrpos( $path, '.' ); return strtolower( $i ? substr( $path, $i + 1 ) : '' ); } /** * Get an associative array containing information about a file in the local filesystem. * * @param string $path Absolute local filesystem path * @param string|bool $ext The file extension, or true to extract it from the filename. * Set it to false to ignore the extension. * @return array */ public static function getPropsFromPath( $path, $ext = true ) { $fsFile = new self( $path ); return $fsFile->getProps( $ext ); } /** * Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case * encoding, zero padded to 31 digits. * * 160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36 * fairly neatly. * * @param string $path * @return false|string False on failure */ public static function getSha1Base36FromPath( $path ) { $fsFile = new self( $path ); return $fsFile->getSha1Base36(); } } /** @deprecated class alias since 1.43 */ class_alias( FSFile::class, 'FSFile' ); PK ! ��P(� � TempFSFileFactory.phpnu �Iw�� <?php namespace MediaWiki\FileBackend\FSFile; use Wikimedia\AtEase\AtEase; use Wikimedia\FileBackend\FSFile\TempFSFile; /** * @ingroup FileBackend */ class TempFSFileFactory { /** @var string|null */ private $tmpDirectory; /** * @param string|null $tmpDirectory A directory to put the temporary files in, e.g., * $wgTmpDirectory. If null, we'll try to find one ourselves. */ public function __construct( $tmpDirectory = null ) { $this->tmpDirectory = $tmpDirectory; } /** * Make a new temporary file on the file system. * Temporary files may be purged when the file object falls out of scope. * * @param string $prefix * @param string $extension Optional file extension * @return TempFSFile|null */ public function newTempFSFile( $prefix, $extension = '' ) { $ext = ( $extension != '' ) ? ".{$extension}" : ''; $tmpDirectory = $this->tmpDirectory; if ( !is_string( $tmpDirectory ) ) { $tmpDirectory = TempFSFile::getUsableTempDirectory(); } $attempts = 5; while ( $attempts-- ) { $hex = sprintf( '%06x%06x', mt_rand( 0, 0xffffff ), mt_rand( 0, 0xffffff ) ); $path = "$tmpDirectory/$prefix$hex$ext"; AtEase::suppressWarnings(); $newFileHandle = fopen( $path, 'x' ); AtEase::restoreWarnings(); if ( $newFileHandle ) { fclose( $newFileHandle ); $tmpFile = new TempFSFile( $path ); $tmpFile->autocollect(); // Safely instantiated, end loop. return $tmpFile; } } // Give up return null; // @codeCoverageIgnore } } PK ! rA� � TempFSFile.phpnu �Iw�� <?php /** * Location holder of files stored temporarily * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file * @ingroup FileBackend */ namespace Wikimedia\FileBackend\FSFile; use MediaWiki\FileBackend\FSFile\TempFSFileFactory; use RuntimeException; use WeakMap; use Wikimedia\AtEase\AtEase; /** * This class is used to hold the location and do limited manipulation * of files stored temporarily (this will be whatever wfTempDir() returns) * * @ingroup FileBackend */ class TempFSFile extends FSFile { /** @var bool Garbage collect the temp file */ protected $canDelete = false; /** @var array Map of (path => 1) for paths to delete on shutdown */ protected static $pathsCollect = null; /** * A WeakMap where the key is an object which depends on the file, and the * value is a TempFSFile responsible for deleting the file. This keeps each * TempFSFile alive until all associated objects have been destroyed. * @var WeakMap|null */ private static $references; /** * Do not call directly. Use TempFSFileFactory * * @param string $path */ public function __construct( $path ) { parent::__construct( $path ); if ( self::$pathsCollect === null ) { // @codeCoverageIgnoreStart self::$pathsCollect = []; register_shutdown_function( [ __CLASS__, 'purgeAllOnShutdown' ] ); // @codeCoverageIgnoreEnd } } /** * Make a new temporary file on the file system. * Temporary files may be purged when the file object falls out of scope. * * @deprecated since 1.34, use TempFSFileFactory directly * * @param string $prefix * @param string $extension Optional file extension * @param string|null $tmpDirectory Optional parent directory * @return TempFSFile|null */ public static function factory( $prefix, $extension = '', $tmpDirectory = null ) { return ( new TempFSFileFactory( $tmpDirectory ) )->newTempFSFile( $prefix, $extension ); } /** * @todo Is there any useful way to test this? Would it be useful to make this non-static on * TempFSFileFactory? * * @return string Filesystem path to a temporary directory * @throws RuntimeException if no writable temporary directory can be found */ public static function getUsableTempDirectory() { $tmpDir = array_map( 'getenv', [ 'TMPDIR', 'TMP', 'TEMP' ] ); $tmpDir[] = sys_get_temp_dir(); $tmpDir[] = ini_get( 'upload_tmp_dir' ); foreach ( $tmpDir as $tmp ) { if ( $tmp != '' && is_dir( $tmp ) && is_writable( $tmp ) ) { return $tmp; } } // PHP on Windows will detect C:\Windows\Temp as not writable even though PHP can write to // it so create a directory within that called 'mwtmp' with a suffix of the user running // the current process. // The user is included as if various scripts are run by different users they will likely // not be able to access each others temporary files. if ( PHP_OS_FAMILY === 'Windows' ) { $tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mwtmp-' . get_current_user(); if ( !is_dir( $tmp ) ) { mkdir( $tmp ); } if ( is_dir( $tmp ) && is_writable( $tmp ) ) { return $tmp; } } throw new RuntimeException( 'No writable temporary directory could be found. ' . 'Please explicitly specify a writable directory in configuration.' ); } /** * Purge this file off the file system * * @return bool Success */ public function purge() { $this->canDelete = false; // done AtEase::suppressWarnings(); $ok = unlink( $this->path ); AtEase::restoreWarnings(); unset( self::$pathsCollect[$this->path] ); return $ok; } /** * Clean up the temporary file only after an object goes out of scope * * @param mixed $object * @return TempFSFile This object */ public function bind( $object ) { if ( is_object( $object ) ) { // Use a WeakMap on PHP >= 8.0 to avoid dynamic property creation (T324894) if ( PHP_VERSION_ID >= 80000 ) { if ( self::$references === null ) { self::$references = new WeakMap; } self::$references[$object] = $this; } else { // PHP 7.4 if ( !isset( $object->tempFSFileReferences ) ) { // Init first since $object might use __get() and return only a copy variable $object->tempFSFileReferences = []; } $object->tempFSFileReferences[] = $this; } } return $this; } /** * Set flag to not clean up after the temporary file * * @return TempFSFile This object */ public function preserve() { $this->canDelete = false; unset( self::$pathsCollect[$this->path] ); return $this; } /** * Set flag clean up after the temporary file * * @return TempFSFile This object */ public function autocollect() { $this->canDelete = true; self::$pathsCollect[$this->path] = 1; return $this; } /** * Try to make sure that all files are purged on error * * This method should only be called internally * * @codeCoverageIgnore */ public static function purgeAllOnShutdown() { foreach ( self::$pathsCollect as $path => $unused ) { AtEase::suppressWarnings(); unlink( $path ); AtEase::restoreWarnings(); } } /** * Cleans up after the temporary file by deleting it */ public function __destruct() { if ( $this->canDelete ) { $this->purge(); } } } /** @deprecated class alias since 1.43 */ class_alias( TempFSFile::class, 'TempFSFile' ); PK ! �9�_" " FSFile.phpnu �Iw�� PK ! ��P(� � \ TempFSFileFactory.phpnu �Iw�� PK ! rA� � � TempFSFile.phpnu �Iw�� PK � b5
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка