views:

55

answers:

3

hi i have to extract the cabfile(.cab) on the server. i am Finding such script which extract cab file but i didn't get it yet. So now i am try to extract using cabarc.exe. But i face the problem that when i run command throuw commandline its work fine but when i give same command to system() or exec() function in php it is not work. code is as follow:

    $command = "c:\\exe\\cabarc X c:\\cab\\data.cab c:\\data\\";
if(($output = system($command,$return) != false)
{
  echo "$return";
}

it is not working when i use same string in commandline it works fine. please any body help me to why it not working what to do tomake it work is ther any rights issue. I had give the execute permission to the site.

thanks

+1  A: 

The 2nd argument to the system function is passed by reference so it needs to be initialized by your code. Also, you should check for false using !== not != because it validates type in addition to value. Additionally, it looks like you've got an unbalanced parenthesis in your if statement. Try this:

$command = "c:\\exe\\cabarc X c:\\cab\\data.cab c:\\data\\";
$return = -1;
$output = system($command, $return);
if($output !== false)
{
    echo "Return value is: " . $return . "\r\n";
    echo "Output is:\r\n" . $output . "\r\n";
}

If that doesn't fix your issue, make sure the PHP user has permissions to access the file.

Asaph
Thanks Asaph for replyI have followed your suggestion. but my problem is still remaining.I have gave full control to the site and folder.but it doesn't work.Is ther any problem in php and iis?thanks for help
jazzy
@jazzy: Try running the PHP program outside of IIS. Try running the PHP program directly on the console.
Asaph
+1  A: 

If you're using NTFS, check your file permissions and make sure the web server can run that executable, open the source file, and write the destination.

NeuroScr
+1  A: 

Another problem might be that the program is not allowed to run cmd.exe, maybe see if the IUSR account can execute this program as system needs to invoke a shell.

Martin