简体   繁体   English

使用Javascript调整图像大小后,如何使用$ _POST通过PHP上传

[英]After resizing image using Javascript, how to upload via PHP using $_POST

Basically I try to code a webpage where users can upload pictures via iPhone/Andoid and Desktop. 基本上我尝试编写一个网页,用户可以通过iPhone / Andoid和桌面上传图片。 These pictures should been saved as thumbnail in ./userupload and the link to this is stored in a MySQL DB. 这些图片应保存为./userupload中的缩略图,其链接存储在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. 我通过简单的HTML表单上传和PHP脚本切出了应该是缩略图的部分,保存了新图片并将链接写入数据库。 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. 这听起来很容易,但现在iPhone图片非常大而且6MB图片的移动上传需要很长时间才能实现3G。 Therefore I looked for a possibility to do the resizing at the clientside with Javascript. 因此,我寻找使用Javascript在客户端进行大小调整的可能性。 Through stackoverflow I found this very helpful little script which I use for resizing now. 通过stackoverflow我找到了这个非常有用的小脚本 ,我现在用它来调整大小。

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. 不幸的是我的Javascript和HTML5技能不是很发达,我不知道如何传递调整大小的图像,现在通过<img>标签与<form>的其他输入一起显示到我的后端php脚本保存图像并将链接写入数据库。 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). 好吧,因为在调整大小的<img> src属性中有一个base64编码的图像,你可以将该值放入隐藏的输入并上传bas64字符串(而不是真实图像)。 Then you can decode the image in your PHP script and save it the way you need. 然后,您可以在PHP脚本中解码图像并以您需要的方式保存它。

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

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