473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Changing disk drive in php under windows(XP) and apache(2.2)

7
I am a newbie at php, and am trying to develop a php script that will return information about the files on the CD in a drive that lives on my apache server.

The "opendir" function allows me to get the file information I want, but it seems that it will not open a directory on a different disk drive.
I have also tried to do this from a command prompt with the same results.

The php documentation makes no reference to changing disk drives, and I now think that php will not allow this.

Can anyone tell me how to do this "directory", or suggest some creative way to accomplish it *without
1. copying the CD to the hard drive
2. using "system" to write an intermediate file

Thanks,

Bob
Apr 6 '07 #1
11 2053
Motoma
3,237 Expert 2GB
Could you post the code you have that doesn't work? I'm not completely sure what you mean when you say that opendir doesn't work for this.
Apr 6 '07 #2
Kugler
7
Hi,

This program is so hacked up from my trying to make it work, that I have to get it back to working like it did before I can post it, so I will put it up in the next day or so...

Thanks ,

Bob
Apr 8 '07 #3
Kugler
7
Hi,

I think this is "cockpit error". After I removed all of the patches and extra stuff, it started working under the command prompt, but I am still having trouble getting apache to run it. It is telling me that I do not have permission to access the CD ( I know that any output text would be unformatted without the html tags).
This is the cd listing code. If you see something wrong would you let me know?

Thanks,

Bob

[PHP]


$CD = "E:\\";
$Root_String = "CD_Root";
$A_Map = array(// array must be in same order as recurse_dir returns fields
// Array Key mySQL field name
'0' => array('DirKey' => 'level', 'DB_Var' => 'NestLevel', 'Label' => "Level From Root"),
'1' => array('DirKey' => 'path', 'DB_Var' => 'Path', 'Label' => "Path From Root"),
'2' => array('DirKey' => 'name', 'DB_Var' => 'FileName', 'Label' => "FileName"),
'3' => array('DirKey' => 'file_perms', 'DB_Var' => 'Attributes', 'Label' => "Permissions"),
'4' => array('DirKey' => 'mod_time', 'DB_Var' => 'Modified', 'Label' => "Date Modified or Copied"),
'5' => array('DirKey' => 'size', 'DB_Var' => 'Size', 'Label' => "Size")
);


// index keys for one line of file info

$A_File_Info = array('CD_Index' => '0',
'FileName' => "",
'Path' => "",
'Size' => "",
'NestLevel' => "",
'Modified' => "",
'Attributes' => "",
'Category' => "",
'Sub_Cat' => "",
'Crippled' => "",
'Rating' => "",
'Installed_On' => ""
);



// main
// Open a known directory, and proceed to read its contents
$DirArray = array();
$DirArray = recur_dir($CD) or die("Could not open $CD"); // get cd dir and file listing
print_r($DirArray);
die();


// end main


function recur_dir($dir) //http://fundisom.com/phparadise/php/directories/recursive_directory_listing
{
$dirlist = opendir($dir);
while ($file = readdir ($dirlist))
{
if ($file != '.' && $file != '..')
{
$newpath = $dir.'\\'.$file;
$level = explode('\\',$newpath);
if (is_dir($newpath))
{ // recurse new directory
$DirArray[] = array(
'level'=>count($level)-1,
'path'=>substr($newpath,1,strlen($newpath)),
'name'=>end($level),
'type'=>'dir',
'file_perms'=>"0x" . dechex(fileperms($newpath)), //filetype($newpath), // mime_content_type($newpath),
'mod_time'=>date("D M j,Y g:i A" , filemtime($newpath)), //DATE_RFC822
'size'=>filesize($newpath),
'content'=>recur_dir($newpath));
}else{ // list files in directory
/*
Note: Because PHP's integer type is signed and many platforms use 32bit
integers, filesize() may return unexpected results for files which are
larger than 2GB. For files between 2GB and 4GB in size this can usually
be overcome by using sprintf("%u", filesize($file)).
Note: The results of this function are cached. See clearstatcache()
for more details.
*/
$S = sprintf("%u", filesize($newpath));
if($S > 1.024e6)
$S = (round(($S/1.024e6), 2) . " mB");
else if($S > 1.024e3)
$S = (round(($S/1.024e3), 2) . " kB");
else
$S .=" Bytes";
$DirArray[] = array(
'level'=>count($level)-1,
'path'=>substr($newpath,1,strlen($newpath)),
'name'=>end($level),
'type'=>'file',
'file_perms'=>"0x" . dechex(fileperms($newpath)),
'mod_time'=>date("D M j,Y g:i A", filemtime($newpath)),
'size'=> $S );
}
}
}
closedir($dirlist);
return $DirArray;

}




[/PHP]
Apr 9 '07 #4
Motoma
3,237 Expert 2GB
What error messages are you getting?
Apr 9 '07 #5
Kugler
7
What error messages are you getting?
I have two different error situations when I try to run this script from firefox (pointed at my website). The most frequent is "forbidden - you don't have permission to access this resource", this occurs even though I am accessing the site from localhost, and have granted full access to localhost in apache.
The second is not really a message, but a recognition issue. When I started changing the apache settings to try and fix the "forbidden" issue, I somehow made the apache/php system think the php file is a plain text file, and it is now downloading the php file instead of executing it.
Any help you can give would be appreciated....

Thanks,

Bob
Apr 9 '07 #6
Motoma
3,237 Expert 2GB
To get PHP to be executed instead of downloading, you will need to modify httpd.conf and add a couple of AddType declarations:
Expand|Select|Wrap|Line Numbers
  1. AddType application/x-httpd-php .php
  2. AddType application/x-httpd-php .php3
  3.  
Perhaps you could post the actual error message for us?
Apr 9 '07 #7
Kugler
7
To get PHP to be executed instead of downloading, you will need to modify httpd.conf and add a couple of AddType declarations:
Expand|Select|Wrap|Line Numbers
  1. AddType application/x-httpd-php .php
  2. AddType application/x-httpd-php .php3
  3.  
Perhaps you could post the actual error message for us?
Thanks for the help on the AddType. That made my server start executing the code.
It is now running the script in a dos box rather than returning text to the browser window. Could I be causing program conflicts by using php in both a "prompt window mode" and in a "browser mode" on the same machine?

I am not getting any "forbidden" error messages in the browser now, but it may be that the execution in a dos box is bypassing the browser, so I don't get the message.
In my apache httpd.conf, there is a line that says :
AddHandler .php "C:/Program Files/PHP/php-win.exe"
I may have added this while I was fumbling (I at least corrected the path).
Should that line be there?

The php script itself runs ok (except for the dos box) in Firefox, but in IE (latest ver), I get an error message in the dos box that says:

PHP Notice: Undefined variable: DirArray in C:\Documents and Settings\Owner\Local Settings\Temporary Internet Files\Content.IE5\LGOTWPX1\List_CD5[1].php on line 96

Line 96 is the "return $DirArray;" at the end of function recur_dir().
The "$" is not missing in the code.

If you want, I can privately put a link to the page somewhere for you to use, but since I am not sure how secure the site is, I would rather not publish the address.

Thanks,
Bob
Apr 10 '07 #8
Kugler
7
Thanks for the help on the AddType. That made my server start executing the code.
It is now running the script in a dos box rather than returning text to the browser window. Could I be causing program conflicts by using php in both a "prompt window mode" and in a "browser mode" on the same machine?

I am not getting any "forbidden" error messages in the browser now, but it may be that the execution in a dos box is bypassing the browser, so I don't get the message.
In my apache httpd.conf, there is a line that says :
AddHandler .php "C:/Program Files/PHP/php-win.exe"
I may have added this while I was fumbling (I at least corrected the path).
Should that line be there?

The php script itself runs ok (except for the dos box) in Firefox, but in IE (latest ver), I get an error message in the dos box that says:

PHP Notice: Undefined variable: DirArray in C:\Documents and Settings\Owner\Local Settings\Temporary Internet Files\Content.IE5\LGOTWPX1\List_CD5[1].php on line 96

Line 96 is the "return $DirArray;" at the end of function recur_dir().
The "$" is not missing in the code.

If you want, I can privately put a link to the page somewhere for you to use, but since I am not sure how secure the site is, I would rather not publish the address.

Thanks,
Bob
Should have said: I am running the browser on the server and connecting to localhost...is is ok to do that?

Thanks again...Bob
Apr 10 '07 #9
Motoma
3,237 Expert 2GB
That this means is that DirArray is not being declared. It is declared inside a couple of conditions, therefor you should put some echo statements in to see which conditions you are actually hitting.
Apr 10 '07 #10
Kugler
7
Hi...

Sorry it took so long to get back to this...have a bunch of stuff happening.

You hit it right on about $DirArray...Its fixed...Thanks!
Its odd, though that Firefox and the command prompt both forgave the error, but IE flagged it...

I found one of my drive issues. The messages were:

[15-Apr-2007 10:28:49] PHP Warning: opendir(E:\): failed to open dir: No such file or directory in C:\Documents and Settings\Owner\Local Settings\Temp\List_CD5-1.php on line 51
[15-Apr-2007 10:28:49] PHP Warning: readdir(): supplied argument is not a valid Directory resource in C:\Documents and Settings\Owner\Local Settings\Temp\List_CD5-1.php on line 52
[15-Apr-2007 10:28:49] PHP Warning: closedir(): supplied argument is not a valid Directory resource in C:\Documents and Settings\Owner\Local Settings\Temp\List_CD5-1.php on line 96

Then I discovered that it helps if there is a CD in the drive....this was a side effect of a sub zero IQ.

I declared (as you suggested) $DirArray. I declared it as an empty shell at the start so it would return a blank array with no CD, now I have to trap the "no CD" error.

The only issue left is the opening of a DOS box for the result. If I don't try to print the array, but just do:
printf("<html><body>Test1"<br></body></html>"); instead,
a DOS box still opens, and the text is not in the browser window (in firefox).
In IE, it asks me if I want to save or run the file. I click "run", and the DOS box opens again....same problem...
This really sounds like an Apache issue, but I am not sure...Do you have any Ideas?

Thanks,

Bob
Apr 15 '07 #11
Motoma
3,237 Expert 2GB
You can safely remove
AddHandler .php "C:/Program Files/PHP/php-win.exe" from your config file.
Apr 16 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave | last post by:
I downloaded PHP w/ Install Shield for Windows and installed it following all the prompts. I wrote a couple of test pages in Dreamweaver MX 2004, and got the http: 404 error message, "page not...
1
by: killu007 | last post by:
I use PHP on a windows xp machine and have problem installing PHP extensions. How can i install php extensions on windows xp. I use apache 2.x. I am particularly interested in installing...
7
by: Sid | last post by:
hello! i am a newbie and 'am trying to install php 5.0.3 on apache 2.0.52 on windows xp sp1. the problem i am getting is whenever i call a .php page in my web browser e.g....
2
by: KeyWest JetSki | last post by:
I have Windows XP Home Edition SP2 and I need to do Web Development. I want to know if anyone has XP Pro running IIS and how is it working? I have SQL 2000 Developer and Frontpage 2003 with asp...
11
by: gregsands | last post by:
Hi Im trying to install PHP 5.05 on Windows XP running Apache 2.0.54 Apache is running fine and ive made all the changes to the pnp.ini file and Apache config file, restarted Apache but all I get...
5
by: comp.lang.php | last post by:
Has anyone had any luck with file zipping utilities for PHP 4-5 and Windows XP with Apache 2.0.53? Following is my code snippet: PHP Code: if ($this->isSuccessful) { // RUN ZIP...
2
by: Romy Sreedharan | last post by:
Hello, I am wondering whether there is a mechanism to clear the Hard Disk Cache using C#? This is for O.S Windows XP regards romy
0
by: anagai | last post by:
hi I have the java bridge library working fine on a windows 2000 and running apache 1.3 but cannot for whatever reason get it to work on windows xp and apache 2.0.5 Ive included the following...
12
by: comp.lang.php | last post by:
Env: Windows XP, Apache 1.33, PHP 5.2.0 <? echo is_dir($_SERVER) . " for dir = " . $_SERVER); ?>
1
by: Gowri | last post by:
Hello, I am new to Python and am trying to setup Apache to serve Python using mod_python. I'm using a Windows XP box. here is a list of steps i followed for the installation: 1. Installed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.