我可以从PHP获取文件的短DOS名称吗?

I want to pass a file path as a parameter to an executable from PHP, and the file path may contain spaces. The executable doesn't seem to handle quotes around the parameter, so I thought maybe I could pass the short DOS name instead of the long name.

Does PHP know anything about the old-style DOS 8.3 file names?

php/win32 ships with the COM/.net extension built-in. You can use it to create a WSH FileSystemObject and then query the ShortPath property of the File object.

<?php
$objFSO = new COM("Scripting.FileSystemObject");
$objFile = $objFSO->GetFile(FILE);
echo "path: ", $objFile->Path, "
short path: ", $objFile->ShortPath;
prints e.g.
path: C:\Dokumente und Einstellungen\Volker\Desktop\test.php
short path: C:\DOKUME~1\Volker\Desktop\test.php

How about backslashing the space?

Home/My Documents/  --> Home/My\ Documents/

You may want to have a look at escapeshellarg() and put the parameter in between double quotes.

You want the GetShortPathName API in Kernel32 on windows. To call this from PHP, you will need to use the Win32 API extension...