Forum Moderators: coopster

Message Too Old, No Replies

only upload file to sql table

         

plus

12:42 pm on Mar 1, 2009 (gmt 0)

10+ Year Member



may be i described variables in not corect way. in sql table weight i described blob. Thanks a lot for help.

<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>

blang

3:28 pm on Mar 1, 2009 (gmt 0)

10+ Year Member



What was the question? You want to insert the uploaded file into a BLOB type column in your database?

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.

plus

4:55 pm on Mar 1, 2009 (gmt 0)

10+ Year Member



Thank you very much. I will try to do that. But this part of code $fname=$_FILES[$uploadfile]['name'];
$fsize=$_FILES[$uploadfile]['size'];
$fweight=$_FILES[$uploadfile]['tmp_name']; is good. May be should be like that
$fname=$_FILES['file1']['name'];
$fsize=$_FILES['file1']['size'];
$fweight=$_FILES['file1']['tmp_name'];

plus

3:44 pm on Mar 2, 2009 (gmt 0)

10+ Year Member



thanks for help . i solved this problem.