![]() |
Using curl to read a file from an external server?
So I have to read a pdf file as an attachment from an external server. I use for the local server:
PHP Code:
PHP Code:
Code:
[content_type] => application/pdfAny ideas? |
You'll have to set the header in your PHP document so that once you've acquired the PDF, it can be treated like a PDF. So before you echo out the PDF's content, add:
php Code:
In fact, remove the above line from the PDF side of things, and move it across to the PHP side where you're using cURL. |
Very nice dude, thanks a bunch. :)
|
To my knowledge, header should be called upon before there is ANY output what so ever? HTML or print/echo? By the way gcbdm, nice script.
|
Yea, definitely. You're spot on. Before ANY output else you will receive a fairly nasty error. Just add the header function before the echo construct.
|
Then I've got a question for ya Wildhoney. Yesterday I saw a script, calling up header in a switch, midpage, with outputs all around. He used sessions & cookies, with my (basically yours) salt script, enhanced IP (browser, lang, windows & IP combined) and a bit more (with the lardge encoding sha1+md5.
Anyways, what's the big deal about header? I really don't get it, but still, I know how to use it. Header can define the page properties but you can use it as a redirect as well. (ofcourse after the header(''); you call up exit(); (with, if you want, a message between the (). So, can you explain this to me? :D |
Quote:
|
Quote:
|
Quote:
So, if you send the body before you issue the header function then because the header function has already been dispatched, you cannot send another header function once the first header has gone. Thus: Send: HTML GET/POST Request -> Receive: HTML Header -> Receive: HTML Body. After the HTML body comes nothing, but more body stuff. With the way HTTP works you cannot set another header function - that is, those items in <head>. To get around this problem you can prevent the body stuff being sent prematurely by using such functions as as the ob_* library. This stores the body in an internal buffer until you tell it to send that buffer to the client. Therefore it allows you to send all the header stuff, still interpret the body as well, but send them in order: header then body.The best way to go about it though is to not use the ob_* library at all and simply create your PHP script so that all PHP is processed before any output is displayed, then just mingle the PHP echoes amongst the HTML. |
Well THAT sure it a lot to take in all at once, but I knew I was right. Header can only be called upon before any output. That is fairly enough to know if you're getting into advanced programming. Well, if you ask me.
I'm going to do some research into the ob_ library you just talked about. Thanks for the explanation Wildhoney! |
Here's a little snippet that usually explains an easy way to suck remote data rather easily.
PHP Code:
For example, if you start ob_start(), and beging flushing out the header and body as it comes, the body won't have to wait for certain block level objects like <TABLE> tags to load fully before they start to show up. Just a little trick you can apply every now and then.. -- Note: was just using the simple curl and ob_ functions to show what they can do together, it's in no way a complete snippet (though it does work). |
| All times are GMT. The time now is 09:33 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0