Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sucithra
Starting Member
7 Posts |
Posted - 2010-10-11 : 05:36:18
|
| i am using sql server 2008:database stucture is:CREATE TABLE [dbo].[fun_gallery]( [file_id] [int] NOT NULL, [file_name] [varchar](50) NOT NULL, [file_type] [varchar](50) NOT NULL, [file_size] [int] NOT NULL, [file_content] [image] NOT NULL, CONSTRAINT [PK_fun_gallery] PRIMARY KEY CLUSTERED $fileName = $_FILES['file']['name'];$tmpName = $_FILES['file']['tmp_name']; $fileSize = $_FILES['file']['size'];$fileType = $_FILES['file']['type'];$fp = fopen($tmpName, 'rb');$content = fread($fp, filesize($tmpName));$content = addslashes($content);fclose($fp); i call the upload function: upload function:function file_upload($max_id,$filename,$filesize,$filetype,$filecontent) { //$file='CAST('.$filecontent.' AS '.'VARBINARY(MAX))'; $safesql = new SafeSQL_ANSI; $continue = 1; $sql_ins_login = "INSERT INTO fun_gallery(" ."file_id,file_name, file_type,file_size,file_content" .") VALUES (" ."%i,'%s', '%s', %i, '%s'" .")"; $sql_ins_login_val = array($max_id,$filename,$filetype,$filesize,$filecontent); $safe_ins_login = $safesql->query($sql_ins_login, $sql_ins_login_val); // echo $safe_ins_login; echo "<br/>"; exit; $qry_ins_login_val = $this->db_link->query($safe_ins_login); if(!$qry_ins_login_val) { $continue = 0; } if($continue) { $this->db_link->commit(); return 1; } else { $this->db_link->rollback(); return 0; } } and this is the download function:function download_file($file_id) { $safesql = new SafeSQL_ANSI; $sql_select_file = "SELECT file_name,file_type,file_type,file_size,file_content FROM fun_gallery where file_id=$file_id"; $qry_select_file = $this->db_link->query($sql_select_file); if ($qry_select_file) { $total_found = $this->db_link->num_rows; } if ($total_found > 0) { $row_get_file = $this->db_link->fetch_row($qry_select_file); return $row_get_file; } } i called up the download function and the stored values frm the database:$file_name = $file_download['file_name'];$file_size = $file_download['file_size'];$file_type = $file_download['file_type'];$file_content = $file_download['file_content'];header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-type: ".$file_type); header("Content-Length: ".$file_size); header("Content-Disposition: attachment; filename=\"".$file_name."\";"); header("Content-Transfer-Encoding: binary"); $html ='';$html ='<html><body>'.htmlspecialchars($file_content).' </body></html>';/*$html ='<html><body>Test </body></html>';*/echo $html; when i download the file , its open with something '/0' is there in full file. for image its show some error and for pdf file also..thanks in advance.. |
|
|
Sachin.Nand
2937 Posts |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-10-16 : 05:06:43
|
| Read more about filestream object in BOL.PBUH |
 |
|
|
|
|
|
|
|