使用Javascript调整图像大小后,如何使用$ _POST通过PHP进行上传 [英] After resizing image using Javascript, how to upload via PHP using $_POST

查看:141
本文介绍了使用Javascript调整图像大小后,如何使用$ _POST通过PHP进行上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我尝试编写一个网页,用户可以通过iPhone / Andoid和桌面上传图片。这些图片应该作为缩略图保存在./userupload中,并且链接存储在MySQL DB中。



我通过简单的HTML表单上传和PHP脚本剪出应该是缩略图的部分,保存新图片并将链接写入数据库。这听起来很简单,但现在iPhone图片真的很大,而且6MB图片的移动上传需要很长时间。因此我寻找了一种可能性,在Javascript的客户端调整大小。通过stackoverflow,我发现这个非常有用的小脚本,我现在用它来调整大小。



不幸的是,我的Javascript和HTML5技能并不是非常发达,我不知道如何传递已调整大小的图像,该图像现在通过< img> ; 标记和< form> 的其他输入一起放到我的后端php脚本中,以保存图像并将链接写入数据库。您有任何想法吗?



提前谢谢

解决方案

好吧,由于您在调整大小的< img> src 属性中有base64编码图像c>,您可以将该值放入隐藏的输入中,并上传bas64字符串(而不是实际图像)。然后,您可以解码您的PHP脚本中的图像并以您需要的方式进行保存。


Basically I try to code a webpage where users can upload pictures via iPhone/Andoid and Desktop. These pictures should been saved as thumbnail in ./userupload and the link to this is stored in a MySQL DB.

I realized it with simple HTML form upload and a PHP Script cutting out the part which should be the thumbnail, saving the new picture and write link to database. It sounds easy but what is tricky that iPhone pictures are really big nowadays and mobile upload of a 6MB picture would take a long time cia 3G. Therefore I looked for a possibility to do the resizing at the clientside with Javascript. Through stackoverflow I found this very helpful little script which I use for resizing now.

Unfortunately my Javascript and HTML5 skills are not very developed and I don't know how to pass the resized image, which is now displayed through a <img> tag, together with the other input of the <form>, to my backend php script to save the image and write the link into the database. Do you have any ideas?

Thank you in advance

解决方案

Well, since you have a base64 encoded image in src attribute of your resized <img>, you could put that value into a hidden input and upload the bas64 string (instead of real image). Then you can decode the image in your PHP script and save it the way you need.

这篇关于使用Javascript调整图像大小后,如何使用$ _POST通过PHP进行上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆