Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CD Drive

Status
Not open for further replies.

bmodi

Programmer
Oct 8, 2001
5
US
I'm a newbie at PHP....and I would like to be able to browse the contents of my CD drive (but only if a CD is the drive). Here is the code that i used in an ASP page....
<%@Language=JScript%>
<%
var fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
function getDrvInfo(drvPath, id)
{
var drv = fso.GetDrive(fso.GetDriveName(drvPath));
var info = new Array();
if (drv.IsReady) {
info[0] = &quot;<a href=\&quot;browse.asp?vol=&quot;+id+&quot;>&quot; + drv.VolumeName + &quot;</a>&quot;;
info[1] = drv.TotalSize / 1024 + &quot; Kb&quot;;
info[2] = drv.FreeSpace / 1024 + &quot; Kb&quot;;
}
else {
info[0] = &quot;Not Ready!&quot;;
info[1] = &quot;N/A&quot;;
info[2] = &quot;N/A&quot;;
}
return info;
}

var vol = new Array();
// Load the 3 CD Drives....
vol[0] = getDrvInfo(&quot;E:&quot;, 1);
vol[1] = getDrvInfo(&quot;F:&quot;, 2);
vol[2] = getDrvInfo(&quot;G:&quot;, 3);
%>

However I cannot get this type of functionality with PHP...is it possible?

Thanx in Advance,
Bhavik Modi
 
It is not possible with PHP to do client side tasks. The only browse stuff of a local file system comes from HTML, when u want to upload files.
U are using activeX in the above example, in PHP u need to use activeX, Flash or JavaScript to do that. mcvdmvs
-- &quot;It never hurts to help&quot; -- Eek the Cat
 
I am NOT trying to browse the contents of the client's CD-ROM drive...I am trying to browse the contents of the CD-ROM on the server.

Here is the code that does browsing....(Assumes that the cd drive is loaded).

<?php
$path = &quot;&quot;;
$vol = urldecode($HTTP_GET_VARS[&quot;vol&quot;]);
// Convert the &quot;volume&quot; to logical drive
if ($vol == 1) {
$path = &quot;E:&quot;;
}
else if ($vol == 2) {
$path = &quot;F:&quot;;
}
else if ($vol == 3) {
$path = &quot;G:&quot;;
}
else {
// Invalid volume...only have 3 drives
header(&quot;location: error.php&quot;);
exit;
}

$dir = $HTTP_GET_VARS[&quot;dir&quot;];
$dir = urldecode(&quot;${dir}&quot;);
$path = &quot;${path}${dir}&quot;;

// Sub Folders Array
$childFolders = array();
// Array of files in the directory
$childFiles = array();

$d = opendir($path);
while ($file_name = readdir($d)) {
if ($file_name != &quot;.&quot; && $file_name != &quot;..&quot;) {
$entryName = &quot;${path}${file_name}&quot;;
if (is_dir($entryName)) {
// Add the entry to the folders array
$encoded_name = urldecode(&quot;${dir}${file_name}/&quot;);
$childFolders[count($childFolders)] = ${encoded_name}&quot;;
}
else if (is_file($entryName)) {
// Add the entry to the files array
$encoded_name = urldecode(&quot;${dir}${file_name}&quot;);
$childFiles[count($childFiles)] = &quot;${encoded_name}&quot;;
}
}
}
closedir($d);
?>

Bhavik Modi
 
as far as i can tell it's impossible to change drives in php. i couldn't find any information regarding drive letters.
when using the
Code:
pathinfo
function you can see that it doesn't return a drive letter. only a path.
if i come across something i'll post it here. (-:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top