Re: passthru() on Win98 ??
| From: | Mike Flynn | Date: | Tue, 26 Feb 2002 16:59:06 +0000 |
| Subject: | Re: passthru() on Win98 ?? | ||
| References: | 1 2 3 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-12306@lists.php.net to get a copy of this message | ||
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:
Hmm in my case there is no file to link to. The pdf document doesn't exist, it's generated on-the-fly. Take this example: test.php contains: <? function topdf($file, $options = "") {-- Mike Flynn - Burlington, VT -- mike @ mikeflynn.net http://www.mikeflynn.net/ home=>work=>home=>store=>home [adbusters]header("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 from "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... Yes, this has been documented extensively on the web. The fix is to put a pdf extension at the end of the url call to your script that is returning the pdf file. You can use an arbitrary filename ending in .pdf, or you can use the actual filename of the .pdf file, which would be preferable so that if the user tries to save the .pdf file, the default filename is correct. So what this means is that the script that is linking to your .pdf-returning script needs to know the filename/that it is a .pdf file, ahead 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 the PDF</a>\n"; ?> -Mike At 03:09 PM 2/26/2002 +0100, Sviss Cobazor wrote:However, sigh, IE seems to have a bug so that Acrobat Reader is onlyloadedwhen the URL ends with ".pdf" aka IE doesn't give a rats about the header sent to it. Using Telnet I can see that the pdf page is returned correctly but when using IE I still get a blank page due to the fact that no (pre-generated) pdf 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 handled asapdf document (as in load Acrobat Reader)? "Sviss Cobazor" <sviss@nospam.dk> wrote in message news:20020226102428.17377.qmail@pb1.pair.com...ask meIt seemed that it was Putty itself that wouldn't work for me (don'tfoundwhy). So I used Telnet and it worked. After having my advicor (this is a education project) visiting me weitout why that passthru() function didn't work. It's very simple really, passthru() doesn't allow spaces in paths so "C:\program files\etc." becomes "C:\program" => false path. Removing the application (htmldoc.exe) to "C:\" instead did the job. For anyone else having same problems this is the correct way to type(mybrowser.example): <? 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 themyselfThanks for your time Court, I wouldn't have thought of using Telnetparticular.:) ~ Sviss "Court Shrock" <ShrockC@inhs.org> wrote in message news:25E1EA6CA52DD311A525009027725B55041424E7@exchange1.inhs.org...typedTo explain the 400 bad request, you most likely had a typo when youinthe 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 toarewhether or not the passthru function is doing things properly, youyourbrowserverifying what is being sent to the browser by simulating what thewould send to your webserver and then what the browser is getting in response. It will all start to make sense when you start seeingcase,filesfileoutput--of course, in the request that I had you type, I assumed thewebserverthat returns the pdf is named "index.php" or whatever file yourwill retrieve when it gets a root "/" request. If this is not the-- 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.phpyou-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpneed to replace the "GET / HTTP/1.1" line with "GET /yourfile.phpHTTP/1.1"or even "GET /yourfile.php?var1=whatever__yougettheidea HTTP/1.1". passthru 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.4 OpenSSL/0.9.6 X-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.4 OpenSSL/0.9.6 X-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 data is properly 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.