devofash Posted August 9, 2007 Share Posted August 9, 2007 hey guys need some help. I'm trying to upload/download script which uploads pdf files into mssql server. i'm having some problems hope you guys can help me out. i've been here http://www.phpfreaks.com/forums/index.php/topic,146750.0.html ... the script works when I use txt and image files but when i upload pdf's I can't download it. I get an error saying "There was an error opening this document. The file is damaged or could not be repaired." the datatype of the field is set to image i'm posting my code below, please help me out. UPLOAD.PHP $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $location = $_POST['location']; $datastring= file_get_contents($tmpName); // Unpacks from a binary string into an array according to the given $data=unpack("H*hex", $datastring); $fp = fopen($tmpName, 'r'); $content = fread($fp, $fileSize); //$content = addslashes($content); fclose($fp); $db = new dbase(); $db->db_connect(); $q = "INSERT INTO casestudies(location, filename, filecontents) ". "VALUES ('$location', '$fileName', 0x".$data['hex'].");"; $r = $db->query($q); GETFILE.PHP $q = "select * from casestudies WHERE id='".$_GET['id']."'"; $results = $db->query($q); $numRows = $db->numRows($results); if($numRows > 0) { while($rows = mssql_fetch_object($results)) { header("Content-type: application/pdf"); header("Content-Disposition: attachment; filename=$rows->filename"); echo $rows->filecontents; } } else { echo "No such file exists on Database"; } I would really appreciate some help . thanx Quote Link to comment https://forums.phpfreaks.com/topic/64059-php-mssql-file-upload-download/ Share on other sites More sharing options...
devofash Posted August 13, 2007 Author Share Posted August 13, 2007 anybody?? .... I could really use some help ... please Quote Link to comment https://forums.phpfreaks.com/topic/64059-php-mssql-file-upload-download/#findComment-322181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.