Re: passthru() on Win98 ??
| From: | Mike Flynn | Date: | Tue, 26 Feb 2002 18:34:08 +0000 |
| Subject: | Re: passthru() on Win98 ?? | ||
| References: | 1 2 3 4 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-12312@lists.php.net to get a copy of this message | ||
It goes into a link to whatever PHP file you're using to return the contents of the .PDF. It would work in the address field in the browser, too. I don't see why you're typing http://localhost/test.php/whatever.pdf into the address field since that isn't the URL I told you to use. I said:
http://whatever/stuff.php?options/desired_filename.pdf
As you can see, instead of stuff.php put the name of the php file that has your code to return the binary contents of the .pdf file. You can follow it with whatever optional parameters you want in the query string (i/e after the '?' question mark), either way, make sure at the very end of the address is a slash '/' followed by the desired filename you want to use, ending in .pdf.
-Mike
At 05:58 PM 2/26/02 +0100, you wrote:
Is the example below meant to go into a link (<a href=***></a>)? Or is it meant for the address field on the browser? If I type "http://localhost/test.php/whatever.pdf" in the address field I get a server error which I was also expecting to be hornest. I don't see how that should work. "Mike Flynn" <mike@mikeflynn.net> wrote in message news:5.1.0.14.2.20020226115736.00a5e120@mikeflynn.net... Use a slash and then the filename.pdf. So http://whatever/stuff.php?options/desired_filename.pdf would do it. It's ok that you aren't linking to a real file, it doesn't matter. Just the file that you want the .pdf document to be known as to the user's browser. At 05:07 PM 2/26/2002 +0100, Sviss Cobazor wrote:-- Mike Flynn -- mike @ mikeflynn . net home => work => home => shop => home [adbusters]Hmm in my case there is no file to link to. The pdf document doesn'texist,it's generated on-the-fly. Take this example: test.php contains: <? function topdf($file, $options = "") {fromheader("Content-Type: application/pdf"); flush();passthru("C:\htmldoc -t pdf14 --quiet --jpeg size A4 --webpage $options \"$file\""); } $url = "http://localhost/whatever.html"; topdf($url); ?> So the idea was to write the address "http://localhost/test.php" and the browser would load Acrobat Reader and show the pdf document generated"whatever.html". So how do I get the ".pdf" added? By typing the address "http://localhost/test.php?.pdf" ? Doesn't seem to work. "Mike Flynn" <mike@mikeflynn.net> wrote in message news:5.1.0.14.2.20020226101043.00a4f470@mikeflynn.net...put aYes, this has been documented extensively on the web. The fix is toreturningpdf extension at the end of the url call to your script that isyouthe pdf file. You can use an arbitrary filename ending in .pdf, orcanyouruse the actual filename of the .pdf file, which would be preferable sothatif the user tries to save the .pdf file, the default filename is correct. So what this means is that the script that is linking tofile,.pdf-returning script needs to know the filename/that it is a .pdfheaderahead of time. So you want to do something like this: <?php $query = 'SELECT strFileFilename FROM tblFiles '; $query .= "WHERE intFileID=$id"; $filename = mysql_result(mysql_query($query), 0); print "<a href=\"/stuff/getfile.php?id=$id/$filename\">Here's thePDF</a>\n";?> -Mike At 03:09 PM 2/26/2002 +0100, Sviss Cobazor wrote:loadedHowever, sigh, IE seems to have a bug so that Acrobat Reader is onlywhen the URL ends with ".pdf" aka IE doesn't give a rats about thewhensent to it. Using Telnet I can see that the pdf page is returned correctly but(pre-generated)using IE I still get a blank page due to the fact that noaspdf document is sent to it and therefore the URL doesn't contain a "whatever.pdf" ind the end and therefore doesn't load Acrobat Reader. Look at this example: header("Content-Type: application/pdf"); flush(); passthru("C:\htmldoc -t pdf14 --quiet --jpeg size A4 --webpage \"http://localhost/whatever.html\""); This works fine with Telnet (where output is nonsense), but doesn't with IE (where the output would make sense). Does anyone have a solution to this? How to get IE to understand that the data sent to it is to be handleda(don'tpdf document (as in load Acrobat Reader)? "Sviss Cobazor" <sviss@nospam.dk> wrote in message news:20020226102428.17377.qmail@pb1.pair.com...It seemed that it was Putty itself that wouldn't work for meask mewewhy). So I used Telnet and it worked. After having my advicor (this is a education project) visiting mefoundsoout why that passthru() function didn't work. It's very simple really, passthru() doesn't allow spaces in pathsjob."C:\program files\etc." becomes "C:\program" => false path. Removing the application (htmldoc.exe) to "C:\" instead did thetypeFor anyone else having same problems this is the correct way toitTelnetbrowser.(myexample): <? function topdf($filename, $options = "") {$optionsheader("Content-Type: application/pdf"); flush(); passthru("C:\htmldoc -t pdf14 --quiet --jpeg size A4 --webpage\"$filename\""); } ?> This function now works and sends the result pdf directly to theThanks for your time Court, I wouldn't have thought of usingmyselfnews:25E1EA6CA52DD311A525009027725B55041424E7@exchange1.inhs.org...:) ~ Sviss "Court Shrock" <ShrockC@inhs.org> wrote in messageyouTo explain the 400 bad request, you most likely had a typo whenyouparticular.typedinthe HTTP request. The request is case-sensitive and verysomehow.Mostlikely, the "Host: localhost" portion of the request messed upwebserverWhen you get a "HTTP/1.1 200 OK" response, that means that thetestaccepted the request and will process your request. In order towhether or not the passthru function is doing things properly,aretheverifying what is being sent to the browser by simulating whatgetting inbrowserwould send to your webserver and then what the browser istheyourresponse. It will all start to make sense when you start seeingfilesoutput--of course, in the request that I had you type, I assumedthefilewebserverthat returns the pdf is named "index.php" or whatever file yourwill retrieve when it gets a root "/" request. If this is notcase,/yourfile.phpyouneed to replace the "GET / HTTP/1.1" line with "GETHTTP/1.1".HTTP/1.1"or even "GET /yourfile.php?var1=whatever__yougettheideaOpenSSL/0.9.6passthru is working properly if you see something like: HTTP/1.1 200 OK Date: Mon, 25 Feb 2002 23:20:35 GMT Server: Apache/1.3.20 (Unix) PHP/4.0.6 mod_ssl/2.8.4OpenSSL/0.9.6X-Powered-By: PHP/4.0.6 Transfer-Encoding: chunked Content-Type: application/pdf [lots of binary data] it isn't working if you see something like this: HTTP/1.1 200 OK Date: Mon, 25 Feb 2002 23:20:35 GMT Server: Apache/1.3.20 (Unix) PHP/4.0.6 mod_ssl/2.8.4data isX-Powered-By: PHP/4.0.6 Transfer-Encoding: chunked Content-Type: text/html <html>some stupid html, or nothing at all</html> in which case, I would try a different method to verify that-- Mike Flynn - Burlington, VT -- mike @ mikeflynn.net http://www.mikeflynn.net/ home=>work=>home=>store=>home [adbusters] -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-- Mike Flynn - Burlington, VT -- mike @ mikeflynn.net http://www.mikeflynn.net/ home=>work=>home=>store=>home [adbusters]-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpproperly passing between php and htmldoc.exe. I hope this has addressed some of the confusion. Court-----Original Message----- From: Sviss Cobazor [mailto:sviss@nospam.dk] Sent: Monday, February 25, 2002 5:12 PM To: php-windows@lists.php.net Subject: Re: [PHP-WIN] passthru() on Win98 ?? I followed your instructions and got: HTTP/1.1 400 bad requestDate: Tue, 26 Feb 2002 01:05:57 GMT Server: Apache/1.3.20 (Win32) Connection: close Content-Type: text/html charset=iso-8859-1... And then the same in html source ... (in the putty window) So I didn't get what was expected but either way I'm not sure what to do if I did.