I am trying to open the raw disk on Windows/PHP. (Like /dev/sda
on Linux.)
I tried (as admin):
fopen("\\?\Device\Harddisk1\Partition0");
I have this path from here. Yes, it’s the whole disk and not a partition.
But I get:
fopen(\?DeviceHarddisk1Partition0): Failed to open stream: No such file or directory
I am using PHP 8.2.10.
I also tried these paths but I get the same error:
\?DeviceHarddisk1Partition1
\?DeviceHarddisk0Partition0
\?DeviceHarddisk0Partition1
\?DeviceHarddisk0
\?DeviceHarddisk1
If this is not possible in PHP I’d welcome an explanation why exactly it’s not supported.
I am writing my own data recovery script. It’s already running well on Linux but I want to port it to Windows.
2
Answers
Fundamentally this is a windows issue.
Windows doesn’t work like this.
Congratulations on accidentally discovering a bug in PHP, it lies in this line:
Obviously if the path contains a
?
, php will consider this to be an invalid path.This is quite reasonable, and I don’t think it is worth fixing, because Windows creates aliases for each partition, e.g.
You can use
fopen
to open the next two forms (administrator privileges required).