Does PHP detect (or delete) the current drive letter?

I am trying to find a way for PHP to determine the drive letter of the USB application included in the application, but I was out of luck.

I create a desktop that goes hand in hand with the applications that I installed with portableapps.com. The main desktop and all applications are on a USB drive; PHP files are stored in the xampp USB version.

Currently I have a conditional statement installed, where if I were to click on the desktop icon for one of the portable applications, it will add โ€œ? App = APPNAMEโ€, which will then be picked up by the conditional and open the application.

<?php $app = $_GET['app']; if ($app == 'pidgin') { $addr = "E:/PortableApps/PidginPortable/PidginPortable.exe"; exec ($addr,$output, $return); } ?> 

I want to be able to connect this drive to any computer and not run problems opening applications, so there is a way to remove E: / at the file location and still have them open or at least a way to determine which drive letter is used by USB and change this part of my code based on what it detects?

+4
source share
2 answers

Perhaps you can analyze it from the magic constant __FILE__ . I do not have a Windows computer, but I think it will be the first character. This might work:

 $drive = substr(__FILE__, 0, 1); 
+9
source
 // Returns null if unable to determine drive letter (such as on a *nix box) function driveLetter($path) { return (preg_match('/^[AZ]:/i', $path = realpath($path))) ? $path[0] : null; } // To find drive letter of current file echo "Drive letter is: ", driveLetter(__FILE__); 
+2
source

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


All Articles