473,503 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

View PDF

Slaxer13
106 New Member
Hi again. In the following code, which is being used to view pdf in browser

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   $file = 'uploads/.pdf';
  3.   $filename = 'yolo.pdf';
  4.   header('Content-type: application/pdf');
  5.   header('Content-Disposition: inline; filename="' . $filename . '"');
  6.   header('Content-Transfer-Encoding: binary');
  7.   header('Accept-Ranges: bytes');
  8.   @readfile($file);
  9. ?>
Is it possible to change the line:

Expand|Select|Wrap|Line Numbers
  1.  $filename = 'yolo.pdf';
so that the variable gains the value of another variable which will get its value from a table?

For example if i have this record on a table (which displays all the records in a db):

id=1;
name=marley.pdf;
type:pdf;
size:xxx mb;

If i click on the name of the file i want a variable that will get that name and put it into the code.

the code would be something like this:

Expand|Select|Wrap|Line Numbers
  1.  $filename = '$pdfname';
I hope you understand what i am trying to ask here...
Peace,
Slaxer13
Jun 8 '15 #1
4 1641
computerfox
276 Contributor
Try using the same concept you learned in the other thread....
I don't recommend setting the header like that. Why do you do that?
Jun 8 '15 #2
Slaxer13
106 New Member
Just some code i found out but i am currently working on it with a friend. I'll try thanks ;)
Jun 9 '15 #3
Luuk
1,047 Recognized Expert Top Contributor
You can put any code you like before the line '$filename = 'yolo.pdf';'

as long as you make sure no output is sent to the browser,

because 'headers()' should be send first, or else you get an error: "Warning: Cannot modify header information - headers already sent (output started at script:line)"
Jun 10 '15 #4
computerfox
276 Contributor
I would suggest letting the HTTP protocol generate a natural header. Less code, less worry, and it looks cleaner. I have never seen headers being built like that in PHP on a real site in 10 years.
Jun 11 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
55928
by: js | last post by:
I am trying to create a primary key constraint on a view in the following statement. However, I got an error ORA-00907: missing right parenthesis. If the CONSTRAINT clause is removed, then the...
3
17954
by: M. Mehta | last post by:
It seems that you can not create a materialized view if you are using outer joins...can someone please verify this? Thanks M. Mehta Please follow my example below: created 2 tables:
4
2336
by: Ryan | last post by:
Bit of an obscure one here, so please bear with me. I have two copies of a database which should be identical. Both have a complex view which is identical. I can open the views and the data is as...
8
2594
by: Jef Driesen | last post by:
I'm implementing some image processing algorithms in C++. I created a class called 'image' (see declaration below), that will take care of the memory allocations and some basic (mathematical)...
4
2221
by: Neil | last post by:
I just resolved a strange situation I was having with an ODBC linked SQL 7 view in an Access 2000 MDB file, and I'm trying to get some understanding as to what happened. The linked view was...
12
2613
by: Neil | last post by:
I previously posted re. this, but thought I'd try again with a summary of facts. I have an Access 2000 MDB with a SQL Server 7 back end. There is a view that is linked to the database via ODBC...
10
8770
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung...
0
3214
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
1
6319
by: Nogusta123 | last post by:
Hi, I have had a lot of problems getting web pages, master pages and content pages to render in VS2005 design view the same as they would in Internet Explorer. I did a lot of looking on the...
6
7031
by: Neil | last post by:
I had a strange situation with a view in SQL 7, that I could use some input on. I had a very simple view -- select a, b, c from table1 where x=y and z=q. Field a in table1 originally was varchar...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.