Can I get the short name of the DOS file from PHP?

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

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

+3
source share
4 answers

php / win32 comes with a built-in COM / .net extension . You can use it to create the WSH FileSystemObject , and then request the ShortPath property of the File Object .

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

escapeshellarg() .

+1

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

+1
source

How about backspace dropping?

Home/My Documents/  --> Home/My\ Documents/
0
source

Source: https://habr.com/ru/post/1710623/


All Articles