|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
using system() to execute pkzip??
Hi,
I am trying to use pkzip to compress documents. I am running a windows PC, so I am trying to execute a DOS command. I have so far: <?php $pkzip="C:/Progra~1/Apache~1/Apache/readwr~1/pkzip.exe"; $pkzipdirectory="C:/Progra~1/Apache~1/Apache/readwr~1/"; $command=$pkzip." ".$pkzipdirectory."myzip.zip"." ".$pkzipdirectory."mydoc.doc"; system($command); ?> The system() command doestn seem to do anything. Neither does: exec($command); shell_exec($command); In case I would echo the $command and copy the outputtext to the command prompt; it works fine, but how can I execute it from php? kind regards Patrick Last edited by cuboctahedron : March 12th, 2003 at 06:09 AM. |
|
#2
|
|||
|
|||
|
hi,
i'm messing with this at the moment as well. only seems to work with apache, but it looks like thats what you're using, so try path like c:\\path\\to\\pkzip instead of c:/path/to/zip cheers mat |
|
#3
|
|||
|
|||
|
I am running Apache with php4.2 on my windows machine.
The '/' also work on windows. I also tried the backslashed. I am wondering; must I include a line to open the cmd box(command prompt box); bassically the script assumes that I am already runnig a cmb box |
|
#4
|
|||
|
|||
|
shouldn't have to as long as cmd.exe is in your path.
can't believe its not really. maybe try a little test like this and see what you get back, then you'll know if its a path problem..... <?php $test = shell_exec("ping 192.168.0.1"); echo $test; ?> if that works then maybe add the location of zip to your systems path. cheers mat |
|
#5
|
|||
|
|||
|
The ping works ok!
I can do the standard commands alright. If I type: $test=shell_exec("C:/Progra~1/Apache~1/Apache/readwr~1/pkzip.exe C:/Progra~1/Apache~1/Apache/readwr~1/myzip.zip C:/Progra~1/Apache~1/Apache/readwr~1/mydoc.doc"); echo $test; nothing happens I tried: 1)using absolute directories (like above) 2) changing path=, to include the pkzip file (A dos version of pkzip) 3) changing to the 'long' directory notation (e.g progra~1 => program files) HELP.., what am I doing wrong? Patrick |
|
#6
|
|||
|
|||
|
Anyone please? I am using the default php.ini settings. Must I change something there?
|
|
#7
|
|||
|
|||
|
talking of php.ini check safe_mode is off...
i guess 2 things to try, 1. stick pkzip and another file to zip at root of c drive so there's no problem with long / short path nanes 2. copy ping.exe to where pkzip is living and try and hit it there. i ended up sticking my .exe at root of c drive while i'm working on it and its fine... otherwise out of things to try ![]() |
|
#8
|
|||
|
|||
|
Executing commands in the shell from a PHP script only works when the program you are trying to execute resides in your system directory (windows 2000: c:\winnt\system32).
This is the reason why the ping command did work, yet your attempt to use pkzip didnt (even when you include the full patch to it). A work around for this is to create a batch file which does what you want, or which takes variables from the PHP script, and then put this batch script in your system directory. Execute the batch file from the PHP script, and it should work.
__________________
Windows 2000 SP4 Apache v2.0.44 PHP v4.3.1 MySQL v3.23.55 |
|
#9
|
|||
|
|||
|
sankyu is correct. See the last 2 user comments on this page of the manual.
Note: If safe mode is enabled you have to use shell_exec(), not the backtick operator used here. Either way, the batch files should work the same.
__________________
strrev ("grebmil") |
|
#10
|
|||
|
|||
|
Quote:
ah yes, an important detail I forgot to add, thank you. |
|
#11
|
|||
|
|||
|
I'm getting crazy.....
I cannot run pkzip (v2.04) for dos from a php file I did everything you all said:......... - I created a batchfile, in system32 directory, called run.bat - I copied pkzip.exe into system32 directory the batchfile has one single line: ___________________________ c:\windows\system32\pkzip.exe c:\windows\system32\test.zip c:\windows\system32\test.doc ___________________________ The batchfile work allright, regardless of path. my php page has: $test = shell_exec("run.bat"); echo $test; the output (echo $test) is: c:\program files\apache group\apache\htdocs\mywebsite>c:\windows\system32\pkzip.exe c:\windows\system32\test.zip c:\windows\system32\test.doc Anyone 1 more last suggestion for me? (Does anyone have a working script otherwise for me using pkzip?) kind regard Patrick Last edited by cuboctahedron : March 12th, 2003 at 10:13 AM. |
|
#12
|
|||
|
|||
|
Your syntax is wrong, it should look like this;
PHP Code:
and if you want to use the backtick operator: PHP Code:
either way, be sure to end the variable line with a ; which it seems you did not do. Also, when using the backtip operator, take note of the fact that the backtick is not he same character as a single quote. The backtick is located to the left of the number 1, beneath your esc button ps; please use the bb PHP tags when you post PHP code, this makes for easier reading, and syntax highlighting. |
|
#13
|
|||
|
|||
|
You also need to specify the full path to run.bat and make sure that all the dirs and files refered to in your batch file are MS-DOS short names.
|
|
#14
|
|||
|
|||
|
Sorry about the bad syntax, but they were 'copy-pasted' incomplete. I've corrected it
![]() Guys, I really dont know it anymore; I tried rar.exe (instead of pkzip), but not working neither. I mean I am not a newbie, or bad coder. I hope someone else dealt with this matter also. It really baffles me. I don't know why I can only run the standard 'windows' commands like ping, dir,echo.... etc,(via batchfile or not) through PHP, but not an application like pkzip(for DOS). Are there any other considerations I might have forgotten? |
|
#15
|
|||
|
|||
|
I might have a clue!?!?
e.g. I have a batchfile saying: ---------------------------------- echo this batchfile works ---------------------------------- running this with: <?php $test=shell_exec("run.bat "); echo $test; ?> echoos 'echo this batchfile works' Shouldnt the 'echo' NOT be there in the echo $test? It's like it is just reading the line, instead of executing it....... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > using system() to execute pkzip?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|