Form Upload image storage to database

Source: Internet
Author: User
Form Upload images are stored in the database. I want to write data to the database. The data project has numbers, names, and so on.
I would like to ask how to upload an image, write the address in the corresponding form, and submit that each item is saved to the database.


Reply to discussion (solution)

For more information, see php upload images and write the paths to the database.
Http://blog.163.com/leiliuxing2010@126/blog/static/2986935420099291022486/

For more information, see php upload images and write the paths to the database.
Http://blog.163.com/leiliuxing2010@126/blog/static/2986935420099291022486/



Explanation

To upload images, you can choose to upload images in php, Baidu.
You can also select plug-ins, including professional image Upload plug-ins (recommended plupload) and text editor plug-ins (recommended kindeditor) (just like the reply box at the bottom to insert images ).
The open-source framework is directly used for enterprise development, so you do not need to consider uploading.
If you want to learn, you can upload the most primitive php files first.

For Baidu, you can understand it.
Http://zhidao.baidu.com/link? Url = wyTYBtPqh5KjrsWVBbElDKEMvlggc3IAXdOvhG9-DX42uZfHPFybSnSqHkLLko-rNIu1gy0_suV3e3RtgbgxKAvp2KKNk_TdPXf8fDMlt-a

There are examples, explanations, and code.
Http://blog.csdn.net/fdipzone/article/details/39915131

For Baidu, you can understand it.
Http://zhidao.baidu.com/link? Url = wyTYBtPqh5KjrsWVBbElDKEMvlggc3IAXdOvhG9-DX42uZfHPFybSnSqHkLLko-rNIu1gy0_suV3e3RtgbgxKAvp2KKNk_TdPXf8fDMlt-a


Read This
I also need to save it to the database and read the image address to assign a value to the form. how can I do this?

There are examples, explanations, and code.
Http://blog.csdn.net/fdipzone/article/details/39915131



The image is converted to a binary stream and saved to the database.
I want to upload the image to a folder on the server, and assign the image path address in the form.
Click Upload> Select File Box> image Confirmation Form> Save Image address, and then fill in other information for submission.
Is there any such thing?

Is it necessary to first upload the temporary file (in the same way as that) and then use move_uploaded_file () to move it to the directory I want to specify?
Then assign a value to the directory/images in the form. JPG.
In this case, I want to teach you how to implement it, but there is still a sense of code.

Is it necessary to first upload the temporary file (in the same way as that) and then use move_uploaded_file () to move it to the directory I want to specify?


There are examples, explanations, and code.
Http://blog.csdn.net/fdipzone/article/details/39915131



The image is converted to a binary stream and saved to the database.
I want to upload the image to a folder on the server, and assign the image path address in the form.
Click Upload> Select File Box> image Confirmation Form> Save Image address, and then fill in other information for submission.
Is there any such thing?

Is it necessary to first upload the temporary file (in the same way as that) and then use move_uploaded_file () to move it to the directory I want to specify?
Then assign a value to the directory/images in the form. JPG.
In this case, I want to teach you how to implement it, but there is still a sense of code.




Is it necessary to first upload the temporary file (in the same way as that) and then use move_uploaded_file () to move it to the directory I want to specify?

Yes. you only need to use move_uploaded_file to move the file to the specified directory.


I wrote an example:

CREATE TABLE IF NOT EXISTS `member` (  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  `username` varchar(50) NOT NULL,  `photo` varchar(200) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


Client.html
         
      Demo                     



Server. php
 '; $ Sqlstr = "select * from member"; $ query = mysql_query ($ sqlstr) or die (mysql_error (); while ($ thread = mysql_fetch_assoc ($ query )) {$ result [] = $ thread;} if ($ result) {foreach ($ result as $ val) {echo $ val ['username'].'
';}}?>


Database name. change the connection username and password to your own.

The $ filename section of server. php does not understand whether it is the specified path to be moved. how can it be changed?

The $ filename section of server. php does not understand whether it is the specified path to be moved. how can it be changed?



$ Filename is the definition, where the file you upload is stored on the server and what the file name is.

For example, $ filename = "1.jpg ";

After the image is uploaded, 1.jpg will be generated in the current directory.


The $ filename section of server. php does not understand whether it is the specified path to be moved. how can it be changed?



$ Filename is the definition, where the file you upload is stored on the server and what the file name is.

For example, $ filename = "1.jpg ";

After the image is uploaded, 1.jpg will be generated in the current directory.



The above is put in the current directory, and the name is changed to a unique name composed of numbers
How can I modify this sentence if I want to save it to the current directory/wx/ss folder?
$ Filename = ".. /wx/ss/time (). substr ($ _ FILES ['photo '] ['name'], strrpos ($ _ FILES ['photo'] ['name'], '. '); "No changes have been made, and no changes have been made.
Add another page

Name and submit do not
Click upload and select "OK Image". The image path is displayed in the image address form.
Whether the title is valid or not is in a table. Therefore, you want to add "name" and "photo" to do not display the title.
After editing, you only need to upload another image and change the image address.
In addition, how can we ensure that the database records and images in the folder are deleted?

$ Filename = time (). substr ($ _ FILES ['photo '] ['name'], strrpos ($ _ FILES ['photo'] ['name'], '. '));

Change

$ Filename = 'wx/SS '. time (). substr ($ _ FILES ['photo '] ['name'], strrpos ($ _ FILES ['photo'] ['name'], '. '));

The wx/ss folder must exist.

Beginner, I am here to learn!
Like the code above,
I have saved the form with uploaded images to the database, so I am touched by QAQ.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.