Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.6k views
in Technique[技术] by (71.8m points)

windows - PHP detect (or remove) current drive letter?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...