Skip to content

fseek does not work with php://input when data is not pre-read #9441

@bohwaz

Description

@bohwaz

Description

$a = fopen('php://input', 'r');

var_dump(stream_get_meta_data($a)['seekable']);

var_dump(ftell($a));
var_dump(fseek($a, 10, SEEK_SET));
var_dump(ftell($a));

Resulted in this output:

bool(true)
int(0)
int(-1)
bool(false)

But I expected this output instead:

bool(true)
int(0)
int(0)
int(10)

If you actually read through to the end of the stream, it becomes seekable:

$a = fopen('php://input', 'r');

while (!feof($a)) {
	fread($a, 8192);
}

var_dump(stream_get_meta_data($a)['seekable']);

var_dump(ftell($a));
var_dump(fseek($a, 10, SEEK_SET));
var_dump(ftell($a));
var_dump(fseek($a, 0, SEEK_END));
var_dump(ftell($a));

Results in what is expected:

bool(true)
int(30320)
int(0)
int(10)
int(0)
int(30320)

PHP Version

PHP/8.1.9

Operating System

Debian stable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions