Jump to content

Upload and download files to MySQL.


gs-gruppen

Recommended Posts

Hi all

 

I have "tried" everything :-)

Surely not - but I can't make this PHP-code working - it seem that the insert into the database works,

as I can see a record - and the blobfield is "[bLOB - 5,7  KiB]"

The size is correct.

BUT download and displaying the PDF file - dosn't work. Either it states the file is un-readable or

it's blank - or damage. The PDF reader has giving me different messages, during my many tests!!!

The PDF-file is already on the server!!!

 

I surely most do something wrong - but what it is - I can't figure out :-(

I will be grateful for some assistance :-)

 

I have created a table with some fields like these:

* key

* Text

* Longblob

* Name

=> See all of them in the code.......

 

 

<?php       

 

$overskrift = "OOOO';

$firma = "FFFFF";

$forfatter = "RRRRRr";

$kategori = "EVENT";

$metadata = "Meta data text";

 

//$fname = "D2008.2.5.doc";

$fname = "Referat.pdf";

$size = filesize("$fname");

$type = 'application/pdf';

 

$fp =fopen($fname, 'rb');

$content = fread($fp, $size);

$content = addslashes($content);

fclose($fp);

 

require("xxxxxxxxxxxxxxx.php");

mysql_query("Insert into arkiv (overskrift, firma, forfatter, kategori, navn, metadata, indhold, type, size)

values ('$overskrift', '$firma', '$forfatter', '$kategori', '$fname', '$metadata', '$content', '$type', $size)");

echo mysql_error();

 

 

header('Content-length:'.$size);

header('Content-type:'.$type);

header('Content-Disposition:attachment;filename='.$fname);

echo $content;

exit();

?>

 

Link to comment
https://forums.phpfreaks.com/topic/193698-upload-and-download-files-to-mysql/
Share on other sites

Hi!

 

That instruction page - is just the one I have been using as guide,

event when I have changed some of the code! I believe it's a good and very clear guide,

and anyhow I can't make it work  :(

 

Anyway - I will run through it again - and let you know - but feel free to come forward with

other corrections  :D

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.