Saving files to a database using PHP is the center of data organization and storage. Various types of data may be processed, including programs, files, reports, and even audio and video data. Individual users can enter only a small part of their resumes in the browser. Therefore, we will demonstrate the upload feature of your resume. Other types of data can be imitated to save files to the database using PHP.
Databases are the centers for data organization and storage. Various types of data may be processed, including programs, files, reports, and even audio and video data. Individual users can enter only a small part of their resumes in the browser. Therefore, we will demonstrate the upload feature of your resume. Other types of data can be imitated in this example.
The first is the information collection page. Select the file to upload. The html code on this page is as follows:
$ LinkID = @ mysql_connect ("localhost", "root", "") or die ("cannot connect to the database server! The database server is not started, or the user name and password are incorrect! ");
$ DBID = @ mysql_select_db ("ResumeDB", $ LinkID) or die ("An error occurred while selecting the database. it may be because the specified database does not exist! ");
$ Result = @ mysql_query ("$ query", $ LinkID); // execute the query and insert the file to the database.
If (! $ Result)
Echo "data insertion failed! ";
Else
Echo "file uploaded successfully! ";
@ Mysql_close ($ LinkID );
// End of file insert. php
? > 〉
With the above Foundation, it should be easy to write a program that reads data from the database. Note that the file is sent to the customer. The server must send a header to the browser, indicating that the data to be sent is a word document. If MSWord is installed on your computer, the browser automatically calls word to display documents.
You can set a hyperlink to download the Word file:
<〈?
// Begin of file show. php
$ LinkID = @ mysql_connect ("localhost", "root", "") or die ("cannot connect to the database server! The database server is not started, or the user name and password are incorrect! ");
$ DBID = @ mysql_select_db ("ResumeDB", $ LinkID) or die ("An error occurred while selecting the database. it may be because the specified database does not exist! ");
Echo "<a href =" download. php? ID = ". $ row [" ID "]." "> View word documents </a> <br> 〉";
}
// End of file show. php
? > 〉
Access the file show. php and you will see a list of personal profile information. Click "view Word document" to view the detailed resume of the corresponding member.
The following file is used to display word documents:
<〈?
// Begin of file download. php
$ LinkID = @ mysql_connect ("localhost", "root", "") or die ("cannot connect to the database server! The database server is not started, or the user name and password are incorrect! ");
$ DBID = @ mysql_select_db ("ResumeDB", $ LinkID) or die ("An error occurred while selecting the database. it may be because the specified database does not exist! ");
$ Query = "select ResuFile from Resume where ID = $ ID ";
// $ ID is the variable passed by the call
$ Result = @ mysql_query ("$ query", $ LinkID );
// Execute the query to read the file content from the database
If (mysql_num_rows ($ result) <1)
{
Echo "no corresponding file found! ";
Exit ();
}
$ Row = mysql_fetch_array ($ result );
$ MFileData = $ row ["ResuFile"];
// Read the resume content (Word file format data)
Header ("Content-type: application/msword ");
// Sending header, indicating that the data to be sent is a word document
Echo $ mFileData;
// Send document data
// End of file download. php
? > 〉
So far, we have implemented the resume submission, database storage, information browsing and other functions, and basically completed the "talent information exchange" framework function.
It should be noted that uploading files and storing databases through PHP is a prominent technical problem. Many websites related to PHP are constantly encountering such problems. These operations depend heavily on the platform and environment settings. Different platform configurations may cause operation failures. The running platform and compilation parameters of the above program are provided for your reference.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.