I have used this style of coding to place a file on my MYSQL database. I'm pretty certain it's stored correctly
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
But i'm having trouble downloading it from the database, and my headers are wrong.
$resumename = get_the_author_meta('resumename', $current_user->ID);
$resumetype = get_the_author_meta('resumetype', $current_user->ID);
$resumesize = get_the_author_meta('resumesize', $current_user->ID);
$content = get_the_author_meta('resumecontent', $current_user->ID);
header("Content-Length: $resumesize");
header("Content-Type: $resumetype");
header("Content-Disposition: attachment; filename=$resumename");
echo($content);
At the moment it returns a corrupt file, of the page (it's loading the actual page data using the headers, rather then the file data).
Anyone know the correct headers to use for this? i have tried @readfile, it's even worse. The file types will be doc, pdf, rtf mainly. Thanks for any help!
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$resumename");
header("Content-Type: $MIME_Type"); //you can use application/pdf for PDF
header("Content-Transfer-Encoding: binary");