Tools, FAQ, Tutorials:
Uploading Files into Database in PHP
How To Upload Files into Database in PHP?
✍: 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("<pre>\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("&/pre>\n"); mysql_close($con); ?>
Note that addslashes() is used to add backslashes to special characters that need to be protected in SQL statements.
⇒ Configuration Settings for File Upload in PHP
⇐ Creating a Database Table to Store Files in PHP
2017-02-20, 2305🔥, 1💬
Popular Posts:
Why I am getting "The Windows SDK version 8.1 was not found" error, when building my C++ application...
Where to find tutorials on Using Azure API Management Developer Portal? Here is a list of tutorials ...
How To Pass Arrays By References? in PHP? Like normal variables, you can pass an array by reference ...
How to use "link" command tool to link objet files? If you have object files previously compiled by ...
How to add request URL Template Parameters to my Azure API operation 2017 version to make it more us...