Downloading Files using PHP from a DB
I've made a large sum of posts recently and if I can figure out this problem with your help then you can say goodbye to my relentless pestering. I've made an upload script that lets user upload files to my db. The fields used in the table in the db are: id,name,size,type,file and respectively correspond to int,varchar,int,varchar,mediumBLOB. I will post the download code below so you guys can take a look at it and tell me what you think the solution is. The problem is that when I print out the data on the screen using echo all i get for the file is some directory which doesn't allow for downloading.
This is an example of what I get:
Name: About Stacks.pdf
Size: 466028 bytes
The only time you can print a file out is by itself (with appropriate headers to tell the browser that an attachment is coming). Trying to print a file into a webpage will end miserbly.
To print out file data you must not have any other output that would cause the headers to be sent such as html or even whitespace. You clearly show a html table being started.
Oddly though you say you're storing the file in a DB, you even use a blob to store it yet your print out is the temporary file name which should be stored as text in the DB!
Thanks for the reply! Can you point me to any tutorials describing some of the stuff you are talking about because I am new to php/mysql and I don't understand some of it.
Two biggies for you:
1) Download flashget and use it to download some files off the internet. Look at how the headers work.
2) Read the tip in my signature about headers already sent.
From both of those you should start to see something that looks familiar. File stream data is sent AFTER the headers however it must have its own UNIQUE headers - it can't share the headers with the html page. Secondly you can't print a file into the html page. Supposing you're offering a mp3 of a .avi file - You can't just print it into the html page and expect the browser to understand it. The browser will just see a bunch of random characters and try to display it as a web page.
|All times are GMT +1. The time now is 02:35 AM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.