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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kugler
    New Member
    • Mar 2007
    • 7

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

    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
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    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.

    Comment

    • Kugler
      New Member
      • Mar 2007
      • 7

      #3
      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

      Comment

      • Kugler
        New Member
        • Mar 2007
        • 7

        #4
        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' => "Permission s"),
        '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($DirArr ay);
        die();


        // end main


        function recur_dir($dir) //http://fundisom.com/phparadise/php/directories/recursive_direc tory_listing
        {
        $dirlist = opendir($dir);
        while ($file = readdir ($dirlist))
        {
        if ($file != '.' && $file != '..')
        {
        $newpath = $dir.'\\'.$file ;
        $level = explode('\\',$n ewpath);
        if (is_dir($newpat h))
        { // recurse new directory
        $DirArray[] = array(
        'level'=>count( $level)-1,
        'path'=>substr( $newpath,1,strl en($newpath)),
        'name'=>end($le vel),
        'type'=>'dir',
        'file_perms'=>" 0x" . dechex(fileperm s($newpath)), //filetype($newpa th), // mime_content_ty pe($newpath),
        'mod_time'=>dat e("D M j,Y g:i A" , filemtime($newp ath)), //DATE_RFC822
        'size'=>filesiz e($newpath),
        'content'=>recu r_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($newpa th));
        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,strl en($newpath)),
        'name'=>end($le vel),
        'type'=>'file',
        'file_perms'=>" 0x" . dechex(fileperm s($newpath)),
        'mod_time'=>dat e("D M j,Y g:i A", filemtime($newp ath)),
        'size'=> $S );
        }
        }
        }
        closedir($dirli st);
        return $DirArray;

        }




        [/PHP]

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          What error messages are you getting?

          Comment

          • Kugler
            New Member
            • Mar 2007
            • 7

            #6
            Originally posted by Motoma
            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

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              To get PHP to be executed instead of downloading, you will need to modify httpd.conf and add a couple of AddType declarations:
              Code:
              AddType application/x-httpd-php .php
              AddType application/x-httpd-php .php3
              Perhaps you could post the actual error message for us?

              Comment

              • Kugler
                New Member
                • Mar 2007
                • 7

                #8
                Originally posted by Motoma
                To get PHP to be executed instead of downloading, you will need to modify httpd.conf and add a couple of AddType declarations:
                Code:
                AddType application/x-httpd-php .php
                AddType application/x-httpd-php .php3
                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\Tempor ary Internet Files\Content.I E5\LGOTWPX1\Lis t_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

                Comment

                • Kugler
                  New Member
                  • Mar 2007
                  • 7

                  #9
                  Originally posted by Kugler
                  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\Tempor ary Internet Files\Content.I E5\LGOTWPX1\Lis t_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

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    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.

                    Comment

                    • Kugler
                      New Member
                      • Mar 2007
                      • 7

                      #11
                      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\L ist_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\L ist_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\L ist_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

                      Comment

                      • Motoma
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3236

                        #12
                        You can safely remove
                        AddHandler .php "C:/Program Files/PHP/php-win.exe" from your config file.

                        Comment

                        Working...