filesize example

public function testFetchRequestData(): void
    {
        $tempFile = (string) tempnam(sys_get_temp_dir(), '');

        $content = fopen(self::TEST_IMAGE, 'rb');
        static::assertIsResource($content);

        $request = new Request([][][][][][]$content);
        $request->query->set('extension', 'png');

        $fileSize = filesize(self::TEST_IMAGE);
        $request->headers = new HeaderBag();
        $request->headers->set('content-length', (string) $fileSize);

        try {
            $this->fileFetcher->fetchRequestData(
                $request,
                $tempFile
            );
            $mimeType = mime_content_type($tempFile);

            static::assertEquals('image/png', $mimeType);
            


    /** * Gets the file size (in bytes). * * @since 2.5.0 * * @param string $file Path to file. * @return int|false Size of the file in bytes on success, false on failure. */
    public function size( $file ) {
        return @filesize( $file );
    }

    /** * Sets the access and modification times of a file. * * Note: If $file doesn't exist, it will be created. * * @since 2.5.0 * * @param string $file Path to file. * @param int $time Optional. Modified time to set for file. * Default 0. * @param int $atime Optional. Access time to set for file. * Default 0. * @return bool True on success, false on failure. */
$temp_file = $this->_createTmpFile($folder->getGlobalName());

        // TODO: handle class instances for $message         if (is_resource($message) && get_resource_type($message) == 'stream') {
            stream_copy_to_stream($message$temp_file['handle']);
        } else {
            fputs($temp_file['handle']$message);
        }
        fclose($temp_file['handle']);

        // we're adding the size to the filename for maildir++         $size = filesize($temp_file['filename']);
        if ($size !== false) {
            $info = ',S=' . $size . $info;
        }
        $new_filename = $temp_file['dirname'] . DIRECTORY_SEPARATOR;
        $new_filename .= $recent ? 'new' : 'cur';
        $new_filename .= DIRECTORY_SEPARATOR . $temp_file['uniq'] . $info;

        // we're throwing any exception after removing our temp file and saving it to this variable instead         $exception = null;

        if (!link($temp_file['filename']$new_filename)) {
            
foreach ($returnedValues as $key) {
            switch ($key) {
                case 'name':
                    $fileInfo['name'] = basename($file);
                    break;

                case 'server_path':
                    $fileInfo['server_path'] = $file;
                    break;

                case 'size':
                    $fileInfo['size'] = filesize($file);
                    break;

                case 'date':
                    $fileInfo['date'] = filemtime($file);
                    break;

                case 'readable':
                    $fileInfo['readable'] = is_readable($file);
                    break;

                case 'writable':
                    
echo json_encode([]);
    exit;
}

if (str_starts_with($uri, '/v1/release/update')) {
    header('Content-Type: application/json');
    echo json_encode([
        'version' => '6.5.0.0',
        'release_date' => false,
        'security_update' => false,
        'uri' => 'http://localhost:8060/update.zip',
        'size' => filesize($fileName),
        'sha1' => hash('sha1', (string) file_get_contents($fileName)),
        'sha256' => hash('sha256', (string) file_get_contents($fileName)),
        'checks' => [],
        'changelog' => [
            'de' => [
                'language' => 'de',
                'changelog' => 'Changelog',
            ],
            'en' => [
                'language' => 'en',
                'changelog' => 'Changelog',
            ],

  protected function compareFiles($file1$file2) {
    $compare_size = filesize($file1->uri) - filesize($file2->uri);
    if ($compare_size) {
      // Sort by file size.       return $compare_size;
    }
    else {
      // The files were the same size, so sort alphabetically.       return strnatcmp($file1->name, $file2->name);
    }
  }

  /** * Generates a test file. * * @param string $filename * The name of the file, including the path. The suffix '.txt' is appended * to the supplied file name and the file is put into the public:// files * directory. * @param int $width * The number of characters on one line. * @param int $lines * The number of lines in the file. * @param string $type * (optional) The type, one of: * - text: The generated file contains random ASCII characters. * - binary: The generated file contains random characters whose codes are * in the range of 0 to 31. * - binary-text: The generated file contains random sequence of '0' and '1' * values. * * @return string * The name of the file, including the path. */

  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    // The file itself might not exist or be available right now.     $uri = $this->getFileUri();
    $size = @filesize($uri);

    // Set size unless there was an error.     if ($size !== FALSE) {
      $this->setSize($size);
    }
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    

  public function __construct(ImageToolkitInterface $toolkit$source = NULL) {
    $this->toolkit = $toolkit;
    if ($source) {
      $this->source = $source;
      $this->getToolkit()->setSource($this->source);
      // Defer image file validity check to the toolkit.       if ($this->getToolkit()->parseFile()) {
        $this->fileSize = filesize($this->source);
      }
    }
  }

  /** * {@inheritdoc} */
  public function isValid() {
    return $this->getToolkit()->isValid();
  }

  
        $filename = wp_generate_block_templates_export_file();

        if ( is_wp_error( $filename ) ) {
            $filename->add_data( array( 'status' => 500 ) );

            return $filename;
        }

        $theme_name = basename( get_stylesheet() );
        header( 'Content-Type: application/zip' );
        header( 'Content-Disposition: attachment; filename=' . $theme_name . '.zip' );
        header( 'Content-Length: ' . filesize( $filename ) );
        flush();
        readfile( $filename );
        unlink( $filename );
        exit;
    }
}
$mime['type'] = mime_content_type( $file );
}

if ( $mime['type'] ) {
    $mimetype = $mime['type'];
} else {
    $mimetype = 'image/' . substr( $filestrrpos( $file, '.' ) + 1 );
}

header( 'Content-Type: ' . $mimetype ); // Always send this. if ( ! str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) {
    header( 'Content-Length: ' . filesize( $file ) );
}

// Optional support for X-Sendfile and X-Accel-Redirect. if ( WPMU_ACCEL_REDIRECT ) {
    header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
    exit;
} elseif ( WPMU_SENDFILE ) {
    header( 'X-Sendfile: ' . $file );
    exit;
}

require_once ABSPATH . 'wp-admin/admin-header.php';

update_recently_edited( $file );

if ( ! is_file( $file ) ) {
    $error = true;
}

$content = '';
if ( ! empty( $posted_content ) ) {
    $content = $posted_content;
} elseif ( ! $error && filesize( $file ) > 0 ) {
    $f       = fopen( $file, 'r' );
    $content = fread( $ffilesize( $file ) );

    if ( str_ends_with( $file, '.php' ) ) {
        $functions = wp_doc_link_parse( $content );

        if ( ! empty( $functions ) ) {
            $docs_select  = '<select name="docs-list" id="docs-list">';
            $docs_select .= '<option value="">' . esc_html__( 'Function Name&hellip;' ) . '</option>';

            foreach ( $functions as $function ) {
                
$field->$method(null);
        $this->assertEquals(['name' => '', 'type' => '', 'tmp_name' => '', 'error' => \UPLOAD_ERR_NO_FILE, 'size' => 0]$field->getValue(), "->$method() clears the uploaded file if the value is null");

        $field->$method(__FILE__);
        $value = $field->getValue();

        $this->assertEquals(basename(__FILE__)$value['name'], "->$method() sets the name of the file field");
        $this->assertEquals('', $value['type'], "->$method() sets the type of the file field");
        $this->assertIsString($value['tmp_name'], "->$method() sets the tmp_name of the file field");
        $this->assertFileExists($value['tmp_name'], "->$method() creates a copy of the file at the tmp_name path");
        $this->assertEquals(0, $value['error'], "->$method() sets the error of the file field");
        $this->assertEquals(filesize(__FILE__)$value['size'], "->$method() sets the size of the file field");

        $origInfo = pathinfo(__FILE__);
        $tmpInfo = pathinfo($value['tmp_name']);
        $this->assertEquals(
            $origInfo['extension'],
            $tmpInfo['extension'],
            "->$method() keeps the same file extension in the tmp_name copy"
        );

        $field->$method(__DIR__.'/../Fixtures/no-extension');
        $value = $field->getValue();

        
static::assertInstanceOf(ImageType::class$type);
    }

    private function getAudioTypeDetector(): AudioTypeDetector
    {
        return $this->getContainer()->get(AudioTypeDetector::class);
    }

    private function createMediaFile(string $filePath): MediaFile
    {
        static::assertIsString($mimeContentType = mime_content_type($filePath));
        static::assertIsInt($filesize = filesize($filePath));

        return new MediaFile(
            $filePath,
            $mimeContentType,
            pathinfo($filePath, \PATHINFO_EXTENSION),
            $filesize
        );
    }
}
// ----- Check the file size                         clearstatcache();
                        if (!is_file($v_header['filename'])) {
                            $this->_error(
                                'Extracted file ' . $v_header['filename']
                                . 'does not exist. Archive may be corrupted.'
                            );
                            return false;
                        }

                        $filesize = filesize($v_header['filename']);
                        if ($filesize != $v_header['size']) {
                            $this->_error(
                                'Extracted file ' . $v_header['filename']
                                . ' does not have the correct file size \''
                                . $filesize
                                . '\' (' . $v_header['size']
                                . ' expected). Archive may be corrupted.'
                            );
                            return false;
                        }
                    }
                }
return 0;
    }

    private static function formatPath(string $path, string $baseDir): string
    {
        return preg_replace('~^'.preg_quote($baseDir, '~').'~', '.', $path);
    }

    private static function formatFileSize(string $path): string
    {
        if (is_file($path)) {
            $size = filesize($path) ?: 0;
        } else {
            if (!is_dir($path)) {
                return 'n/a';
            }

            $size = 0;
            foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS | \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)) as $file) {
                if ($file->isReadable()) {
                    $size += $file->getSize();
                }
            }
        }
Home | Imprint | This part of the site doesn't use cookies.