How to upload a file in phpMySQL database

It is very easy just at first you have to  create a table in mysql under a database with five fields like as  description, data, filename, filesize, filetype and  write the following code

//…………………………………upload.html…………………………………………………\\

<html>
<body>
<form method=”post” action=”upload1.php” enctype=”multipart/form-data”>
Description:<br>
<input type=”text” name=”form_description” size=”40″>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”1000000″>
<br>File to upload:<br>
<input type=”file” name=”form_data” size=”40″>
<p><input type=”submit” name=”submit” value=”submit”>
</form>
</body>
</html>

then write an another php program like as

//…………………………..upload.php………………………………………………\\

<?php
mysql_connect(“localhost”,”username”,”password”);
mysql_select_db(“database_name”);
$data = addslashes(fread(fopen($form_data, “r”), filesize($form_data)));
$result=MYSQL_QUERY(“INSERT INTO uploads (description, data,filename,filesize,filetype) “. “VALUES (‘$form_description’,’$data’,’$form_data_name’,’$form_data_size’,’$form_data_type’)”);
$id= mysql_insert_id();
print “<p>File ID: <b>$id</b><br>”;
print “<p>File Name: <b>$form_data_name</b><br>”;
print “<p>File Size: <b>$form_data_size</b><br>”;
print “<p>File Type: <b>$form_data_type</b><p>”;
?>

ok done.. you try yourself

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: