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, 5049👍, 0💬
Popular Posts:
How To Display a Past Time in Days, Hours and Minutes? - MySQL FAQs - Managing Tables and Running Qu...
What is PMP(project management plan)? The project management plan is a document that describes the p...
How To Change System Global Area (SGA)? - Oracle DBA FAQ - Introduction to Oracle Database 10g Expre...
What is V model in testing? V model map’s the type of test to the stage of development in a project....
An application needs to load a library before it starts to run, how to code? One option is to use a ...