Anybody..please check this code for me..i'm using php and phpMyAdmin for database
this is my sql statement to insert to database..
memo.php
[code=php]$id = $_SESSION['uid'];
$usr = $_SESSION['user_name'];
$userlevel = $_SESSION['user_level'];
$connection=mysql_connect("localhost","root","") or die(mysql_error());
$db=mysql_select_db("memo",$connection) or die ("Error:".mysql_error());
$dep_code=$POST['txtBahagian'];
$unit_code=$POST['txtUnit'];
$post_code=$POST['txtJawatan'];
$vip_code = $POST['txtSalinan'];
$date=$POST['txtTarikh'];
$memo_title = $POST['txtPerkara'];
$memo_title2 = $_POST['txtMemo'];
if ($_POST['btnHantar']==Hantar)
{
if((empty($vip_code)) || (empty($date)) || (empty($memo_title)) || (empty($memo_title2)))
{
header("Location:memoError.php");
}
else
{
$semi_rand = md5( time() );
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$data = chunk_split( base64_encode( $data ) );
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_type};\n" .
" name=\"{$file_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$file_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
$file_name= $FILES['uploadedfile']['name'];
$file_mime_type= $FILES['uploadedfile']['type'];
$file_length= $_FILES['uploadedfile']['size'];
$file_data= $FILES['uploadedfile']['data'];
$file_data= file_get_contents($FILE['uploadedfile']['tmp_name']);
$sql="INSERT INTO history(staff_id,vip_code,memo_date,memo_title,memo_title2,dep_code,unit_code,post_code,name,type,size,data) values('$id','$vip_code','$date','$memo_title','$memo_title2','$dep_code','$unit_code','$post_code','$file_name','$file_mime_type','$file_length','$file_data')";
$result=mysql_query($sql) or die (mysql_error());
$sql2="INSERT INTO userhistory(staff_id,vip_code,memo_date,memo_title,memo_title2,dep_code,unit_code,post_code,name,type,size,data) values('$id','$vip_code','$date','$memo_title','$memo_title2','$dep_code','$unit_code','$post_code','$file_name','$file_mime_type','$file_length','$file_data')";
$result2=mysql_query($sql2) or die (mysql_error());
header("Location:hantarMemo_jaya.php");
}
}
?> [/code]
this is my download.php process
<?php
if(isset($_GET['id']))
{
$connection=mysql_connect("localhost","root","") or die(mysql_error());
$db=mysql_select_db("memo",$connection) or die ("Error:".mysql_error());
$idp = $_GET['id'];
$query = "SELECT name,type,size,data FROM userhistory where history_id='$idp'";
$result = mysql_query($query) or die('Error, query failed');
list($file_name, $file_type, $file_length, $file_data) = mysql_fetch_array($result);
header("Content-length: $file_length");
header("Content-type: $file_type");
header("Content-Disposition: attachment; filename=$file_name");
echo $file_data;
exit;
}
?>
and this is my database..
history_id int
staff_id int
vip_code varchar
memo_date varchar
memo_title varchar
memo_title2 varchar
dep_code varchar
unit_code varchar
post_code varchar
name varchar
type varchar
size int
data blob
the name,type,size and data is for upload file.the problem now is...i can download and save the uploaded file but when i try to view it..it is empty.for example..if i upload an image..after i save it or try to open it...no pereview available for that image..same goes to ms word...when i try to open it..it is empty...why is this happen...and one more thing..all are succesfully insert to database except the data(blob).in the database...it show like this for the data..[BLOB -0B]...Is it because of the data is empty is the reason why the uploaded file cannot be open....somebody..please help me..