fileperms

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Gets file permissions
<?php fileperms(string $filename): int|false
<?php             return chmod($path, $mode);

        }



        return substr(sprintf('%o', fileperms($path)), -4);

    }
<?php         file_put_contents(self::$tempDir.'/file.txt', 'Hello World');

        $files = new Filesystem;

        $files->chmod(self::$tempDir.'/file.txt', 0755);

        $filePermission = substr(sprintf('%o', fileperms(self::$tempDir.'/file.txt')), -4);

        $expectedPermissions = DIRECTORY_SEPARATOR === '\\' ? '0666' : '0755';

        $this->assertEquals($expectedPermissions, $filePermission);

    }
<?php     private function getFilePermissions($file)

    {

        $filePerms = fileperms($file);

        $filePerms = substr(sprintf('%o', $filePerms), -3);



        return (int) base_convert($filePerms, 8, 10);
<?php         $location = $this->prefixer->prefixPath($path);

        clearstatcache(false, $location);

        error_clear_last();

        $fileperms = @fileperms($location);



        if ($fileperms === false) {

            throw UnableToRetrieveMetadata::visibility($path, error_get_last()['message'] ?? '');
<?php     private function assertFileHasPermissions(string $file, int $expectedPermissions): void

    {

        clearstatcache(false, $file);

        $permissions = fileperms($file) & 0777;

        $this->assertEquals($expectedPermissions, $permissions);

    }
<?php     protected function setLocalPhar($localFilename, $newFilename, $backupTarget = null)

    {

        $io = $this->getIO();

        @chmod($newFilename, fileperms($localFilename));




        if (!$this->validatePhar($newFilename, $error)) {
<?php                 if (method_exists($zip, 'setExternalAttributesName')) {

                    $perms = fileperms($filepath);
<?php             if ($originIsLocal) {


                @chmod($targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111));



                if ($bytesCopied !== $bytesOrigin = filesize($originFile)) {

                    throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
<?php                 throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);

            }



            @chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());



            $this->rename($tmpFile, $filename, true);

        } finally {