About the image in the site and management of warehousing!
Source: Internet
Author: User
I have many years of experience in the development of the Web site, the image upload and management has been very headache. The earliest used to upload pictures with FTP, but each upload, the client will download Plug-ins. To later the no component upload, although the solution without the client, but the picture on the site management appears a bit messy:
1, put the picture directory to have writable, can delete the permission.
2, cannot duplicate the name, therefore solves the picture naming method.
3, such as pictures for the release of the news when the upload, when you want to delete the news, to write another code to delete the picture. Because of the possibility of a permission relationship, the speed at which the page runs is affected when it is not deleted or deleted.
4, also can picture easily by other website, hotlinking.
Therefore, I think the modules uploaded in the picture warehousing, centralized management is good!
What to do: Create a new table, used to store the image of the binary data, an automatically add an ID number. Upload pictures, the image of the binary data into the warehouse, and then get the picture ID number, in the reference picture record as long as the ID number can be recorded!
Warehousing procedures (for example, ASP):
Demo1.asp
<%
' Picbriny for picture binary data. As for how to get the picture binary data from the form, you can find the principle of no component uploading on the Internet.
' Table name pic
' Column name image is used to store binary data for a picture
' Column name ID automatically adds a
Rs. Open "Pic", conn,1,3
Rs. AddNew ()
Rs. Fields ("image"). AppendChunk Picbriny
Rs. Update
' Here you can get the ID number of the Picture: Rs.fields ("ID")
Rs. Close
%>
Picture displayed on the page:
Demo2.html
<body>
Display a picture with ID 1 in the Library
</body>
Picture out of the library program (for example, ASP):
Demo3.asp
<%
Id=request ("id")
Rs. Open "SELECT Image from pic where id=" &id,conn,1,1
Response.BinaryWrite RS ("image"). GetChunk (7500000)
Rec.close
%>
To sum up can solve the above problem!
1, the picture is released from the catalog after the library, do not ignore the issue of permissions!
2, the picture has its own ID number in the table, will not have the duplicate question!
3, when the reference picture of the record to be deleted, just in the library to delete more than one record!
4, if you want to prevent hotlinking only in the library program: demo3.asp Add verification can!
5, convenient for other kinds of picture Management!
The thought of so many now, of course, brings with it some problems:
The requirements of the system database increased, upload a few m of the picture may be affected by speed, of course, the system performance is good, strongly recommend the use of this scheme.
Code than before directly put the picture in the directory, complex! So if the site is not a lot of pictures used, or do not use this scheme!
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service