
May 17th, 2002, 04:14 AM
|
|
Moderator
|
|
Join Date: Apr 2002
Posts: 404
Time spent in forums: 1 Day 21 m 10 sec
Reputation Power: 7
|
|
heres the code for my store.php4 file please tell me what i need to change, also here is my getdata.php4 file tell me what i need to fix. also i turned on magic quotes but when i upload the file to the database it's a zero instead of 1,2 3 and so forth. sorry for the hassle guys....
PHP Code:
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
// code that will be executed if the form has been submitted:
if ($submit) {
// connect to the database
// (you may have to adjust the hostname,username or password)
MYSQL_CONNECT("localhost","blah");
mysql_select_db("mysql");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$f orm_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</BODY>
</HTML>
getdata.php4
PHP Code:
<?php
if($id) {
server:
@MYSQL_CONNECT("localhost","blah");
@mysql_select_db("mysql");
$query = "select bin_data,filetype from binary_data where id=$id";
$result = @MYSQL_QUERY($query);
$data = @MYSQL_RESULT($result,0,"bin_data");
$type = @MYSQL_RESULT($result,0,"filetype");
Header( "Content-type: $type");
echo $data;
};
?>
|