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, 5276👍, 0💬
Popular Posts:
How can JavaScript make a Web site easier to use? That is, are there certain JavaScript techniques t...
What is the difference between CALL_FORM, NEW_FORM and OPEN_FORM? CALL_FORM: start a new form and pa...
In C#, what is a weak reference? Generally, when you talk about a reference to an object in .NET (an...
What is the FP per day in your current company?
How To Compile a JUnit Test Class? Compiling a JUnit test class is like compiling any other Java cla...