如何在表单中添加简单的图片上传?
我有一个 html 表单。我想添加一个简单的图像上传功能,它将图像发送到名为“next.php”的 php 页面。关于如何做有什么建议吗?
I have a html form. I want to add a simple image upload feature to it and it will be send the image to a php page called "next.php". Any suggestions on how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建如下 HTML 表单:
您的“next.php”文件可以处理与此类似的图像:
此时,您可以通过检查类型并确保它只是 jpg、gif、png 或种类。我建议将图像复制为 2 或 3 种尺寸(拇指、中型、原始),然后从临时目录中将其删除。您可以使用 ImageMagick 调整图像大小,然后使用 文件系统 功能用于移动和删除临时上传。
Create an HTML form like the following:
Your "next.php" file could handle the image similar to this:
At this point, you can make it more secure by checking the type and ensuring it's only jpg, gif, png, or of the sort. I would recommend copying the image into 2 or 3 sizes (thumb, medium, original), and deleting it from the temporary directory. You could use ImageMagick to resize the images and then use the filesystem functions to move around and delete temporary uploads.
我不知道有什么方法可以在客户端与文件
input
进行交互,因此您需要在服务器端验证/验证上传的文件(在“next.php”中)脚本),但这应该足够了:I'm not aware of any means to interact with a file
input
on the client-side, so you'll need to verify/validate the uploaded file server-side (within the 'next.php' script), but this should be enough: