I made an intranet page that allows me to easily manage my quicklaunch icons in Windows. I wanted to be able to drag-sort them and on new boxes, easily deploy them. Worked great, until I ran into a weird snag. If a shortcut's target has spaces, it changes the spaces to underscores. In the process of debugging, I made a simple makeshortcut.php with it all hardcoded:
$shell = new COM("WScript.Shell");
$shortcut = $shell->CreateShortcut("\\\\solenth\\ql$\\017 - AutoHotKey - Primary.lnk");
$shortcut->TargetPath = "p:\\misc\\ahk\\AutoHotKey - Primary.ahk";
$shortcut->Arguments = "";
$shortcut->IconLocation = "p:\\misc\\ahk\\AutoHotKey_Blue.ico";
$shortcut->Description = "AutoHotKey";
$shortcut->WorkingDirectory = "p:\\misc\\ahk";
echo $shortcut->TargetPath;
$shortcut->save();
When I run it via makeshortcut.php in my browser, I see: P:\misc\ahk\AutoHotKey_-_Primary.ahk
If I open cmd and change into the webserver's folder and run it, I see: P:\misc\ahk\AutoHotKey - Primary.ahk
Any idea why the web server is replacing spaces with underscores? At first I said "ahh, my workstation's PHP installation is not the same as the web server" but I then RDP'd into the webserver and went to the PHP folder that is used by the server and ran the script, and it still worked fine. So it's only when actually ran from the web that it does this.
I'm perplexed. Any suggestions?
Update: I just had an idea. I made a C# console app that creates a shortcut. Hardcoded as in the PHP. I run it in the command prompt, works. I call exec to run it from PHP and it does the same underscore thing. Now I'm really flummoxed.
OS: Server 2012 R2 PHP: 8.3.1 Web Server: IIS 8
I can't explain exactly why it happens, but Lex Li's comment about how old Server 2012 R2 is made me think well, maybe it is related to age. So I made a VM and installed a modern server OS with newer IIS and the problem resolved itself.
Now since it could be any number of things that are different between the two servers, but the application itself is the exact same. So while I cannot definitively point to old IIS as a problem, I'd recommend if having the same problem under 2012 to test your app on a newer platform instead.