Forum Moderators: coopster
<html>
<body>
<center>upload file</center>
<br>
<br>
select file.
<br>
<form method="POST" >
<input type="file" name="file1" enctype="multipart/form-data" size="30">
<input type="submit" value="send" name="click">
</form>
<br>
<br>
<?php
if(isset($_POST['click']))
{
$db_connection=mysql_connect("localhost","#*$!#*$!x","vvvvvvvv")
or die("not connection");
mysql_select_db("#*$!#*$!xx",$db_connection)
or die("can not find");
$uploaddir = '/home/#*$!#*$!#*$!/public_html/baze';
$uploadfile = $uploaddir . basename($_FILES['file1']['name']);
$fname=$_FILES[$uploadfile]['name'];
$fsize=$_FILES[$uploadfile]['size'];
$fweight=$_FILES[$uploadfile]['tmp_name'];
$write = "INSERT INTO upload (name,size,weight) VALUES ('$fname','$fsize','$fweight')";
mysql_query($write,$db_connection) or die('did not write');
move_uploaded_file($_FILES[$uploadfile]['tmp_name'],$uploadfile);
mysql_close($db_connection);
}
?>
</body>
</html>
</body>
</html>
First I would suggest reviewing the PHP manual article on handling file uploads [us3.php.net].
If you want to insert the file into a BLOB column, you have to do two things; first you have to access the actual temporary file on the filesystem (usually stored in /tmp or C:\Temp, wherever your php.ini config file directs it to go) via the $_FILES['file1']['tmp_name'] index. Once you have access to that file, you need to read it's contents into a string using file_get_contents() [php.net]. Making sure it's the right size helps avoid truncation errors. Then just point the string variable containing the file contents to the database as you would any other data, inserting it into the BLOB column you've setup.