mercredi 27 mai 2015

Access windows directory from a web application PHP

I'm New to PHP programming. I'm searching for a solution. After googling a lot, finally i'm here.

My Assignment is like : 'My web application have to detect the device connected to the PC with a name say "My_DEVICE" and if it is found programtically, i should generated a file and keep it in the device. If device is removed and again connected, i should check for a directory as per some....specifications and upload the images into the server'.

I have done it in my local XAMPP server, it's working fine. Whereas when i upload it into the server, i facing the problem. Please help me.

My Code as follows:

for($i = 'C'; $i < 'Z'; $i++)
    {
        // Try to grab the volume name
        if (preg_match('#Volume in drive [a-zA-Z]* is (.*)\n#i', shell_exec('dir '.$i.':'), $m)) 
        {
            //$volname = ' ('.$m[1].')';

            if ($m[1]=='MY_DEVICE')
            {
                $path = $i.":/";
                if ($dh = opendir($path)) 
                {
                    if(file_exists("myfile.txt"))
                    {
                       //my logic here
                       echo "file already exists";
                    }
                    else
                    {
                        $file = fopen("myfile.txt", "w") or die("Unable to open file!");
                        $id=$myid."\r\n";                   
                        fwrite($file, $id);                         
                        fwrite($file, $name);
                        fclose($file);
                    }
                }
                $device = 0;
        }
        else
        {
            //echo "No SMARTSCOPE device";
            $device++;
        }
    }
}

    if($device==0)
    {       
         echo '<h1 align="center" style="padding-top:40px">You Plugged-in Device !!</h1><br />';
    }
    else
    {
         echo '<h1 align="center" style="padding-top:40px">No Device detected !</h1><br />';
    }

When i debugged, i came to know that shell_exec unable to find the path. How to access windows directory from a web application. Is any api's are avaiable? or any libraries are available?

Please help and guide me in the situation. Thanks in Advance !!




Aucun commentaire:

Enregistrer un commentaire