Forum Moderators: coopster

Message Too Old, No Replies

PHP exec Problem

         

andrewsmd

4:37 pm on Jun 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to winzip a file with php. Does know how to do this I am having trouble with it in PHP. I know php can zip files, but I also have a batch file that zips files the way I want. Accomplishing this task either way works for me. Here is my deal, I have a file name VABCBS## the ## are incremented daily from 01-99 then reset to 01. I can get the file name and all of that, that is not a problem. I just cannot figure out how to zip the file. Also, I have some other batch files I would like to run, they are in the same directory as my php files. For some reason however the exec() function will not work. Let's say I have test.bat in the same folder as all of my php files. When I run
if(exec('test.bat')){
echo"file ran";
}//if
else{
echo"file not ran";
}//else
I always get the false. Anyone know why? Thanks in advance,

coopster

7:46 pm on Jun 20, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If 'test.bat' is not in your system path you are more than likely going to have to give the full path to the executable, such as C:\path\to\test.bat

However, rather than jumping through hoops trying to use WinZip and execute a batch file in Windows you might do yourself a favor and use the PHP Zlib Compression [php.net] functions. Much easier. Example link on that manual page.

andrewsmd

1:19 pm on Jun 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes I got a zip function to start working. However I still need to execute batch files from PHP. I have passed the full path in and it still will not execute it. I know my path is correct because I move, copy, delete, and rename files from the same path. Any other suggestions. Thanks,

coopster

1:34 pm on Jun 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It may be a safe_mode issue. Have a look at this manual page on Program execution Functions [php.net] and the corresponding pages for safe mode information.

npwsol

4:20 pm on Jun 24, 2008 (gmt 0)

10+ Year Member



What environment are you running it in? In whatever environment, you need to make sure the PHP executable/user has permissions to access the files in question; since it's a batch script permissions are especially pertinent here. I would set up a dedicated PHP user for security purposes, but I have admit that I don't know how to accomplish that.

If this is set up already, my apologies, but we are looking for a needle in a haystack here.