Discuss using system() to execute pkzip?? in the PHP Development forum on Dev Shed. using system() to execute pkzip?? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 458
Time spent in forums: 2 Days 13 h 54 m 38 sec
Reputation Power: 10
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.
Posts: 45
Time spent in forums: 15 m 8 sec
Reputation Power: 11
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
Posts: 458
Time spent in forums: 2 Days 13 h 54 m 38 sec
Reputation Power: 10
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)
Posts: 38
Time spent in forums: < 1 sec
Reputation Power: 9
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
Posts: 458
Time spent in forums: 2 Days 13 h 54 m 38 sec
Reputation Power: 10
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.
Posts: 38
Time spent in forums: < 1 sec
Reputation Power: 9
Your syntax is wrong, it should look like this;
PHP Code:
$test = shell_exec("run.bat");
echo $test;
and if you want to use the backtick operator:
PHP Code:
$test = `run.bat`;
echo $test;
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.
Posts: 458
Time spent in forums: 2 Days 13 h 54 m 38 sec
Reputation Power: 10
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?
Posts: 458
Time spent in forums: 2 Days 13 h 54 m 38 sec
Reputation Power: 10
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.......