Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Uploaded Files to a Table
How To Uploaded Files to a Table? - PHP Script Tips - Uploading Files to Web Servers
✍: FYIcenter.com
To store uploaded files to MySQL database, you can use the normal SELECT statement as shown in the modified processing_uploaded_files.php listed below:
<?php
$con = mysql_connect("localhost", "", "");
mysql_select_db("fyi");
$error = $_FILES['fyicenter_logo']['error'];
$tmp_name = $_FILES['fyicenter_logo']['tmp_name'];
$size = $_FILES['fyicenter_logo']['size'];
$name = $_FILES['fyicenter_logo']['name'];
$type = $_FILES['fyicenter_logo']['type'];
print("\n");
if ($error == UPLOAD_ERR_OK && $size > 0) {
$fp = fopen($tmp_name, 'r');
$content = fread($fp, $size);
fclose($fp);
$content = addslashes($content);
$sql = "INSERT INTO fyi_files (name, type, size, content)"
. " VALUES ('$name', '$type', $size, '$content')";
mysql_query($sql, $con);
print("File stored.\n");
} else {
print("Upload faield.\n");
}
print("\n");
mysql_close($con);
?>
Note that addslashes() is used to add backslashes to special characters that need to be protected in SQL statements.
2007-04-19, 5241👍, 0💬
Popular Posts:
What will happen in these three cases? if (a=0) { //somecode } if (a==0) { //do something } if (a===...
How to make elements invisible? Change the "visibility" attribute of the style object associated wit...
How to create a thread in a program? You have two ways to do so. First, making your class "extends" ...
How To Select All Columns of All Rows from a Table? - MySQL FAQs - SQL SELECT Query Statements with ...
In which event are the controls fully loaded ? Page_load event guarantees that all controls are full...