Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to find a way for PHP to detect the drive letter of the USB my app is on, but I'm not having any luck.

I'm making a desktop which goes hand in hand with the apps I installed from portableapps.com. The main desktop and all the apps are on a USB drive; the PHP files are stored in the USB version of xampp.

Currently I have a conditional statement set up where if I was to click a desktop icon for one of the portable apps, it would append "?app=APPNAME" which would then be picked up by the conditional and open the app.

<?php 
$app = $_GET['app'];

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

I want to be able to plug this drive into any computer and not run into problems opening the apps, so is there a way to remove the E:/ in the file location and still have them open or at least a way to detect what drive letter the USB is using and change that part of my code based on what it detects?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
5.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

You may be able to parse it from the __FILE__ magic constant. I don't have any Windows computer, but I guess it will be the first character. So this may work:

$drive = substr(__FILE__, 0, 1);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...