Hi all--
I am working on a script to upload files into MYSQL database. Here is
a snippet:
-------------------------------------------------------------------------
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-type: $fileType");
header("Content-disposition: attachment; filename=$fileName");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $fileSize");
readfile ($fileName);

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'];
                $site = $_POST['site'];
                $year = $_POST['year'];

                $fp = fopen($tmpName, 'r');
                $content = fread($fp, $fileSize);
                $content = addslashes($content);
                fclose($fp);

                if(!get_magic_quotes_gpc())
                {
                        $fileName = addslashes($fileName);
                }


mysql_connect("BLAH", "BLAH", "BLAH") or die(mysql_error());
mysql_select_db("BLAH") or die(mysql_error());
$query = "INSERT INTO db_upload (name, size, type, content, site,
year ) ".
                 "VALUES ('$fileName', '$fileSize', '$fileType', '$content',
'$site', '$year')";
$result = mysql_query($query) or die ("Error in query: $query.
".mysql_error());

--------------------------------------------------------------------------------------------

So if the file is an XCEL file, the type in the database shows as a
'application/vnd.ms-excel' file, size shows the right size. All looks
good in the database.
However when I download the file, the file open in microsoft excel,
and then I get an error stating 'Unable to read file'   This error
happens in PDF, EXCEL, and DOC formats, BUT does not happen in gif,
jpg or txt, those files will open!
Anyone else come across this? Appreciate any insight anyone cares to
offer.
Thanks,

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "PHP 
& MySQL" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/phpmysql?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to