Advertising
HTML
CSS
Java Script
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Shivasurya iniatives
About
Founder: Karumuttu Thiagarajan Chettiar
Located in Thiruparankundram,Madurai
Establishment Year: 1957
Website
vhjvhv
Flickr
Fixed Menu (yes/no)
Disqus Shortname
Comments system
0)
2
3
{
4
5
$fileName = $_FILES['userfile']['name'];
6
7
$tmpName = $_FILES['userfile']['tmp_name'];
8
9
$fileSize = $_FILES['userfile']['size'];
10
11
$fileType = $_FILES['userfile']['type'];
12
13
$fp = fopen($tmpName, 'r');
14
15
$content = fread($fp, filesize($tmpName));
16
17
$content = addslashes($content);
18
19
fclose($fp);
20
21
if(!get_magic_quotes_gpc())
22
23
{
24
25
$fileName = addslashes($fileName);
26
27
}
28
29
mysql_connect("localhost","root","");
30
31
mysql_select_db("upload");
32
33
$query = "INSERT INTO files (name, size, type, content ) ".
34
35
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
36
37
mysql_query($query) or die('Error, query failed');
38
39
echo "
40
File $fileName uploaded
41
";
42
43
}
44
45
?>
46
?php>
Download File From MySQL
2
3
30
31
When you click the download link, the $_GET[‘id’] will be set. We can use this id to identify which files to get from the database. Below is the code for downloading files from MySQL Database.
1
?php
2
>?php>?php
4
>
2
3
32
33
Download File From MySQL
34
35
58
59
60
61
68
69
?php
62
>?php>?php
36
>?php
4
>
Events
if($_POST['submit'])//Form submit - where 'file' is the file upload HTML element
{
if($_FILES["file"]["error"] > 0)//Check if there is an error
{
$msg = "Error: ".$_FILES["file"]["error"];
}
else
{
if(file_exists("upload/".$_FILES["file"]["name"]))//Checks if file exists
{
$msg = "The file already exists!";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/". $_FILES["file"]["name"]);//Moves the uploaded file from the temporary directory ('tmp_name') to the 'upload/' directory
}
}
}
No Response to "Home"
একটি মন্তব্য পোস্ট করুন