SQL Blob file

I have files stored in a mysql as blob’s how would i retrieve them as downloads.

Anyone have a suggestion

Andy

just put the right header.

e.g.
header(‘Content-Type: image/png’);
header(‘Content-Disposition: attachment; filename=“whatever.png”’);

and then put out the content of the field with echo.

I have been onto php net and had a look under headers as you suggest above. I came across this and have played about with it for a bit but I am not getting an output

[php]

<?php $file = $row['name']; while (strpos($file)==false) { $file = substr($file); // cut the first char. } header ('Content-type: application/'.$file); header('Content-Disposition: attachment; filename="'.$file.'"'); $tmp = file_get_contents($row['name']); echo $tmp; ?>

[/php]

I’m not sure whether its the file type that is causing the problem. The extension is .mxp

i thougt the file itself is in the database, isn’t it?

what errors are u getting with error_reporting(E_ALL) ?

substr and strpos need 2 parameter!

the file itself is in the database. I am not getting any errors

and the $file string is echoing ok so am not losing the contents.

Its just not doing anything apart from loading hte page

heres what i have now.

[php]
$file = $row[‘content’];
header(“Content-type:application/x-mmxp”);// It will be called downloaded.pdf
header(“Content-Disposition:attachment;filename=’”.$file."’");// The PDF source is in original.pdf
readfile($file);
[/php]

The $row[‘content’] is the blob file on the database is that right.

i have no idea how ur db is looking like.

i guess u’ll need something like:
[php]header(“Content-type: application/x-mmxp”);
header(‘Content-Disposition: attachment; filename="’.addslashes($row[‘name’]).’"’);
echo $row[‘content’];[/php]

All that this does is echo the file

mxi?a ;IXMMmXmM?x?µS?j?@=;????c©??»?8?jpq??XE[?»??n?}gW??¤??r???7o??y®±d«©R8?'O?)k??&`P?"?|??V6O???#qD-???S~?J?? ?K??|T¶?2? ??M??#?E?9P???L?s ?±V?,V???!p???W??_??????v] ?|K?*??«?_??N???x?u?±?0EgM??????;:?? I ?ey¶h m?ZP?????v?=??J ?=???.·??«?x m§Lh ?8??»S¶?Lh?? 1??u¦?ye?§?B.?sY?¶~7·+?k??w?M??(¤?-???«]??¤?CXT?-i?9?"???> B?PHP Page Counter.htm?a *$TXETrWmD?x?­?[k?0???§~ja¶???- t¶????2?OF?§¶?-?8?¶?_??B?Z m?@??|??f??#????J?bN¶C???t2»??BqsX??-¤?©?k?|??rkM????E???P·?h??O????T?S??±?¦6???z ?8??_G?+q??2?X???4??±Q>?¤a??¤I8????;­¤???¦i?f???µ¬xl?[???36?.?I?????(?$???????+c?Z¶?e?*P?5u{D <????x!®??r~?)?y?µh??-?A?#???] *j??=?????

I tried readfile but nothing happens

The db is

id int(11) NOT NULL auto_increment,
name varchar(30) collate latin1_general_ci NOT NULL default ‘’,
type varchar(30) collate latin1_general_ci NOT NULL default ‘’,
size int(11) NOT NULL default ‘0’,
content blob NOT NULL,
PRIMARY KEY (id)

it was easier to do this :wink:

error_reporting

no output before header

Now I am confused, I cant output anything before

[php]
header(“Content-type: application/x-mmxp”);
header(‘Content-Disposition: attachment; filename="’.addslashes($row[‘name’]).’"’);
echo $row[‘content’];
[/php]

so how can I have $row[‘name’] without

[php]

$query = “SELECT * FROM extensions”;
$dw_ext = mysql_query($query, $dbcon) or die(‘Error, query failed’);
$row = mysql_fetch_assoc($dw_ext);

[/php]

before it???

of cause u cann use these lines before header, because thats not generating output to the browser.

output to the browser is generated by echo/print or by anything outside <?php ?> (even a whitespace character)

Now I get it, Thanks for your help

Sponsor our Newsletter | Privacy Policy | Terms of Service