0

I have written a small php script to handle unzipping for me. I can call it from any other script, in my case from a perl script I have and just pass the relevant filename and target directory. my problem is I'd like to get the filename back to confirm success but I cannot get the php to print out plain text. It always prints back the headers. Can I get php to print without headers? Tried the header_remove but it does not work.

    <?php
    header_remove();
    if (!headers_sent()) {   foreach (headers_list() as $header)     header_remove        ($header); } 
    require("dUnzip2.inc.php");
    $Path = $_GET["path"];
    $save_to = $_GET["save_to"];
    $filename = $_GET["filename"];
    $zip_file = "$Path/$filename";
    $zip = new dUnzip2("$zip_file");
    $zip->debug = 0;
    $zip->unzipAll("$save_to");
    unlink("$Path/$filename");
    echo "$filename was uploaded and unpacked.";
    ?>

The response I get from the script is:

HTTP/1.1 200 OK
Connection: close
Date: Thu, 19 Jul 2012 20:40:04 GMT
Server: Nginx / Varnish
Content-Length: 38
Content-Type: text/html
Client-Date: Thu, 19 Jul 2012 20:40:04 GMT
Client-Peer: 66.86.255.11:80
Client-Response-Num:

Foo.zip was uploaded and unpacked. 

I want it to be just:

Foo.zip was uploaded and unpacked. 

EDIT: SOLVED I got it to work, I was using

    my $response = $ua->request($req)->as_string;

When I should have used

    my $response = $ua->request($req)->content;

in my PERL script, thank you, I was looking at everthing but where I needed to.

mario
  • 144,265
  • 20
  • 237
  • 291
  • Nothing wrong with your script. The issue is certainly how you read out the result string / or possibly how you invoke the script. -- But why use a php script in the first place, and not the normal `unzip` tool? – mario Jul 19 '12 at 20:47
  • 2
    possible duplicate of [What does it mean to run PHP in quiet mode?](http://stackoverflow.com/questions/5777792/what-does-it-mean-to-run-php-in-quiet-mode) – mario Jul 19 '12 at 20:49
  • your right mario, i was looking for exactly that (quiet mode). can it be invoked froma script or only command line? I am surprised how hard it is to get just text output in PHP. Which unzip tool are you referring to? I looked once for perl unzip tools and didn't find any useful ones, this and image manipulation i use php scripts for and just make calls. Everythign else i love perl. – Caleb Jardine Jul 19 '12 at 22:02

2 Answers2

1

These headers come from your server, e.g. the HTTP version and status code are part of the HTTP specs. On the client side you can skip the headers by reading up to the first empty line.

mdo
  • 6,961
  • 3
  • 24
  • 26
0

Make an if, like:

if ( strpos( 'Foo.zip was uploaded', $return) !== false ) {
    echo 'Foo.zip was uploaded and unpacked';
}
Peon
  • 7,902
  • 7
  • 59
  • 100