noppy — 2005-02-28T06:18:38-05:00 — #1
Hi, not sure whether this is a php or mysql question. iam using mysql to store some report files that people may want to look at on my website. They are mainly word.docs but i have a few pdfs that i want to display. The word files work fine when i call them but the pdfs just open dreamweaver on my machine and display as code, or if i save as then it saves it as the php display page i have, which is no use. Why don't the pdfs open properly and how do i cure it. Your help will be much appreciated.
bwarrene — 2005-02-28T08:18:57-05:00 — #2
I may be reading this wrong - but are you storing the path to the pdf file in the database table field? I.e. in a table field called filepath that stores the path tot the pdf - something relative like "media/nameoffile.pdf" so when you call it you can do so within an a href using php?
phptek — 2005-02-28T09:26:57-05:00 — #3
Exactly how are you calling them? Do the PDF files have a .pdf file suffix on them when you select the link or howsoever you access/retrieve them?
Without wanting to sound condesending - but do you have a PDF reader on the machine you wish to open them on like Adobe Acrobat Reader?
noppy — 2005-03-01T05:31:27-05:00 — #4
Hi thanks for the replies, Iam very new to php and mysql so i may have misunderstood what i can actually do with mysql as i was going to store the pdf as binary data within the mysql table. Ive tried it with some word files and that works fine. Is this something that shouldn't be done?. It would make it easier for people in my office to add documents they have done to the website. I do have acrobat reader working on my machine (i don't blame you for asking its always worth checking the simple things first). The display page i am using is below. Thanks for you help.
$query = "select bin_data,filetype from binary_data where id=$id";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0,"bin_data");
$type = @MYSQL_RESULT($result,0,"filetype");
Header( "Content-type: $type");
phptek — 2005-03-01T06:58:25-05:00 — #5
The best idea IMO is to store the path, image/file type maybe even the mime-type in separate fields in your DB.
1: Easier to manage. You can see at a glance in your DB what's "in there" - something that's kinda hard to do with a load of binary data in a BLOB field
2: Less memory intensive - loading a load of binary data into a large field like a BLOB type takes up a load of memory. Compare that with a few strings of text in a VARCHAR field...
Regardless - storing it either way - you should be able to download the document in the appropriate format. Make sure the right mime type is beng sent with the link-click.
PDFs are: application/pdf - so in PHP you would use header("Content-Type: application/pdf"); You may have to futz around with it to get it to work though... you always do...
See this page - I've found it very useful in the past.
seanf — 2005-03-01T15:30:30-05:00 — #6
Moved to a more appropriate forum. See Where should I post my thread? for details
noppy — 2005-03-02T11:25:46-05:00 — #7
Thanks for the help. I ve had a look and the filetype is application/pdf but it still doesn't lauch acrobat when i try and open it. I'll have a play around and see what happens. Cheers
(Sorry i got the wrong forum section)
nicknick — 2005-03-03T18:59:25-05:00 — #8
I am really getting to grips with php now.
The only problem that I am having which I cannot find the answer anywhere is with the use of pdf.
I have a form populate a pdf and have created all the lines with x and y coordinates but what do I do when a field goes over a certain number of characters and the line does not go onto the next one and goes too far across the screen.
How do I tell it to go onto the next line if there is not enough space?
guava — 2005-03-03T19:44:05-05:00 — #9
You could use strlen() to get the number of characters in the string to see if it's too many for a single line. Then you can use substr() to put sections of the strings on each line
nicknick — 2005-03-11T04:29:51-05:00 — #10
that a good idea - can u give me an example