简体   繁体   English

如何同时发送表格数据和图像数据?

[英]How do I send form data and image data at the same time?

I have a script that captures data in a form then writes it into a table. 我有一个脚本,可以捕获表单中的数据,然后将其写入表中。 In the same script I also have a button for users to upload an image. 在同一脚本中,我还有一个按钮供用户上传图像。 The images and form MUST be linked to each other. 图片和表格必须相互链接。 eg if I create a recipe for chocolate cake, a user enters the ingredients and method and an image of the chocolate cake. 例如,如果我创建巧克力蛋糕的配方,则用户输入巧克力蛋糕的成分和方法以及图像。

I'm guessing that would be done using a session however uploading an image is independent from submitting a form ie a user has to click a button to upload an image then submit to store the image into a folder and the path into a database and a separate submit button to write the form data into a database. 我猜测可以使用会话来完成,但是上传图像与提交表单无关,即用户必须单击按钮来上传图像,然后提交才能将图像存储到文件夹中,并将路径存储到数据库和单独的提交按钮可将表单数据写入数据库。 In theory a user could upload 10 images and just one form. 理论上,用户可以上传10张图片和一张表格。 How do I ensure each image is linked to a single form? 如何确保每个图像都链接到一个表单? Is it possible to submit everything in one button click or is there another way to do this? 一次单击即可提交所有内容,还是有另一种方式可以提交?

Link to tutorials would be appreciated. 链接到教程将不胜感激。

使用正确的enctype

<form name="form1" method="post" enctype="multipart/form-data" action="/youraction">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM