I am storing all information in the table, also the type and subtype. This works fine for me when I'm storing doc, xls and txt.
For the upload:
if ($sendfile) {
If(is_uploaded_file($fcontent)) {
$fsize = filesize($fcontent);
$mysqlPicture = addslashes(fread(fopen($fcontent, "r"), $fsize));
$ftype = $fcontent_type;
$farrtype = split("/", $fcontent_type, 2);
$ftype = $farrtype[0];
$fsubtype = $farrtype[1];
if ($ftype == "image") {
$fimagesize = getimagesize($fcontent);
$fimagesizetext = $fimagesize[0]."*".$fimagesize[1];
}
else $fimagesizetext = "";
$sql = "INSERT INTO Files";
$sql .= "(FType, FSubType, FSize, FImageSize, FName, FFileName, FDescription, FContent)";
$sql .= " VALUES('$ftype', '$fsubtype', $fsize";
$sql .= ", '$fimagesizetext', '$fname', '$fcontent_name', '$fdescription', '$mysqlPicture')";
mysql_query($sql)
or die(ferror("$PHP_SELF Insert ($sql)"));
unlink($fcontent);
$fname=$fdescription="";
}
else {
echo"You did not upload any picture";
}
}
And when for sending to the client:
$sql = "SELECT *";
$sql .= " FROM Files";
$sql .= " WHERE FNo=$no";
$result = mysql_query($sql)
or die(ferror("$PHP_SELF ($sql)"));
$row=mysql_fetch_object($result);
if ($row->FType != "image") header("Content-Disposition: attachment; filename=".$row->FFileName);
Header( "Content-type: ".$row->FType."/".$row->FSubType);
// echo "<head><title>$FBeskrivelse</title></head>";
echo $row->FContent;
mysql_free_result($result);
I hope this is what you where looking for, and to help four you?