inicio mail me! sindicaci;ón

How to use Php mysql is saved and output a file

After this locality file uploads a server, the script of the server undertakes saving to the file, have two kinds of kind commonly, one kind is to regard as

The file saves the specific table of contents of the machine to fall, but a variety of discomfort that here has file of a lot of such as to weigh a name to bring, some Cheng

Foreword changes file name automatically, add the name before last sends the means such as time in order to assure the uniqueness of file name, what lost a document so is former

Only then name, inquire through file name specific file information also has a lot of difficulty, go against the centralized management of the file; One kind is an article

The powerful function that the database uses in saving a database, can realize all sorts of operations of the file expediently. What the article uses is

2 kinds of methods.

This group of programs demonstrated, how to pass a document of hard disk the webpage, inside the database that uploads a server, and

Numerate the content of the file.

Service instruction:

Altogether has 5 programs, the specification is as follows:

1.File.sql —The structure that this program should express with the database that arrive [note: What the database uses is Test]

2.Upload.php —Upload watch sheet

3.Submit.php —Upload processing program

4.Show_info.php—Show the file information that uploads partly

5.Show_add.php —Show [download] file

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

(1) File.sql—

/ / brief specification

Save the database structure that uploads the basic information that gets a document, notice to save the field of file content here, use Longtext type

Because common Blob type is the largest,store 64K byte. Additional, the acquiescent configuration of general Php is the biggest upload a file to be 2M, if go up

The document that send is particularly big, not forgot to adjust the setting of Php.ini.

/ / file sourceCreate Table Receive(Id Int NOT NULL Auto_increment, # advocate key, automatic and cumulativeFile_data Longblob, # file contentFile_type Varchar(100) , # file typeFile_name Varchar(255) , # file name File_size Int, # file size

PRIMARY KEY(id) # advocate key

PRIMARY KEY(id) # advocate key

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

(2) Upload.php—

/ / brief specification

Upload an interface, the user chooses a file, refer Submit.php to handle next

Notable is a MAX_FILE_SIZE conceal value region, through installing its VALUE but

With the bulk of the file holding on limitation.

/ / program source

<html>

<head>

<title> file uploads the </title> that express sheet

</head>

<body>

<table>

<form Enctype=’multipart/form-data’ Name=’myform’ Action=’submit.php’ Method=’post’>

<INPUT TYPE = "hidden" NAME = "MAX_FILE_SIZE" VALUE = "1000000 ">

<tr><td> chooses to upload file </td><td>

<input Name=’myfile’ Type=’file’></td></tr>

<tr><td Colspan=’2′><input Name=’submit’ Value=’ uploads ‘ Type=’submit’></td></tr>

</table>

</body>

</html>

In all 3 pages: On one page 1[2] [3] Issue one page

Bookmark:Digg Del.icio.us Reddit

Leave a Comment