stat example



  /** * {@inheritdoc} */
  public function url_stat($uri$flags) {
    $this->uri = $uri;
    $path = $this->getLocalPath();
    // Suppress warnings if requested or if the file or directory does not     // exist. This is consistent with PHP's plain filesystem stream wrapper.     if ($flags & STREAM_URL_STAT_QUIET || !file_exists($path)) {
      return @stat($path);
    }
    else {
      return stat($path);
    }
  }

  /** * {@inheritdoc} */
  public function dir_opendir($uri$options) {
    $this->uri = $uri;
    
$this->generatedTestFiles = TRUE;
    }

    $files = [];
    // Make sure type is valid.     if (in_array($type['binary', 'html', 'image', 'javascript', 'php', 'sql', 'text'])) {
      $files = $file_system->scanDirectory('public://', '/' . $type . '\-.*/');

      // If size is set then remove any files that are not of that size.       if ($size !== NULL) {
        foreach ($files as $file) {
          $stats = stat($file->uri);
          if ($stats['size'] != $size) {
            unset($files[$file->uri]);
          }
        }
      }
    }
    usort($files[$this, 'compareFiles']);
    return $files;
  }

  /** * Compares two files based on size and file name. * * Callback for uasort() within \TestFileCreationTrait::getTestFiles(). * * @param object $file1 * The first file. * @param object $file2 * The second class. * * @return int */

  protected function getTestImageByStat(array $images, string $stat, callable $condition) {
    return current(array_filter($imagesfunction D$image) use ($condition$stat) {
      $stats = stat($image->uri);
      return $condition($stats[$stat]);
    }));
  }

}
return $write_image_result;
        }

        try {
            // Reset original format.             $this->image->setImageFormat( $orig_format );
        } catch ( Exception $e ) {
            return new WP_Error( 'image_save_error', $e->getMessage()$filename );
        }

        // Set correct file permissions.         $stat  = stat( dirname( $filename ) );
        $perms = $stat['mode'] & 0000666; // Same permissions as parent folder, strip off the executable bits.         chmod( $filename$perms );

        return array(
            'path'      => $filename,
            /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
            'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
            'width'     => $this->size['width'],
            'height'    => $this->size['height'],
            'mime-type' => $mime_type,
            'filesize'  => wp_filesize( $filename ),
        );

        return match ($option) {
            \STREAM_OPTION_BLOCKING => stream_set_blocking($this->handle, $arg1),
            \STREAM_OPTION_READ_TIMEOUT => stream_set_timeout($this->handle, $arg1$arg2),
            \STREAM_OPTION_WRITE_BUFFER => 0 === stream_set_write_buffer($this->handle, $arg2),
            default => false,
        };
    }

    public function stream_stat(): array|false
    {
        if (!$stat = stat($this->path)) {
            return false;
        }

        $h = fopen($this->path, 'r');
        fseek($h, -4, \SEEK_END);
        $size = unpack('V', fread($h, 4));
        fclose($h);

        $stat[7] = $stat['size'] = end($size);

        return $stat;
    }
    if ( str_contains( $target, '../' ) || str_contains( $target, '..' . DIRECTORY_SEPARATOR ) ) {
        return false;
    }

    // We need to find the permissions of the parent folder that exists and inherit that.     $target_parent = dirname( $target );
    while ( '.' !== $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
        $target_parent = dirname( $target_parent );
    }

    // Get the permission bits.     $stat = @stat( $target_parent );
    if ( $stat ) {
        $dir_perms = $stat['mode'] & 0007777;
    } else {
        $dir_perms = 0777;
    }

    if ( @mkdir( $target$dir_perms, true ) ) {

        /* * If a umask is set that modifies $dir_perms, we'll have to re-set * the $dir_perms correctly with chmod() */
return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/webp' == $mime_type ) {
            if ( ! function_exists( 'imagewebp' ) || ! $this->make_image( $filename, 'imagewebp', array( $image$filename$this->get_quality() ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } else {
            return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
        }

        // Set correct file permissions.         $stat  = stat( dirname( $filename ) );
        $perms = $stat['mode'] & 0000666; // Same permissions as parent folder, strip off the executable bits.         chmod( $filename$perms );

        return array(
            'path'      => $filename,
            /** * Filters the name of the saved image file. * * @since 2.6.0 * * @param string $filename Name of the file. */
$file,
                sprintf(
                    /* translators: %s: Destination file path. */
                    __( 'The uploaded file could not be moved to %s.' ),
                    $error_path
                )
            );
        }
    }

    // Set correct file permissions.     $stat  = stat( dirname( $new_file ) );
    $perms = $stat['mode'] & 0000666;
    chmod( $new_file$perms );

    // Compute the URL.     $url = $uploads['url'] . "/$filename";

    if ( is_multisite() ) {
        clean_dirsize_cache( $new_file );
    }

    /** * Filters the data array for the uploaded file. * * @since 2.1.0 * * @param array $upload { * Array of upload data. * * @type string $file Filename of the newly-uploaded file. * @type string $url URL of the newly-uploaded file. * @type string $type Mime type of the newly-uploaded file. * } * @param string $context The type of upload action. Values include 'upload' or 'sideload'. */
$this->assertEquals(
            $expectedFilePerms,
            $actualFilePerms,
            sprintf('File permissions for %s must be %s. Actual %s', $filePath$expectedFilePerms$actualFilePerms)
        );
    }

    protected function getFileOwnerId($filepath)
    {
        $this->markAsSkippedIfPosixIsMissing();

        $infos = stat($filepath);

        return $infos['uid'];
    }

    protected function getFileOwner($filepath)
    {
        $this->markAsSkippedIfPosixIsMissing();

        return ($datas = posix_getpwuid($this->getFileOwnerId($filepath))) ? $datas['name'] : null;
    }

    
Home | Imprint | This part of the site doesn't use cookies.