将png图片从JavaScript传递到PHP(错误:请求URI太大)

Pass png image from JavaScript to PHP (Error: Request-URI Too Large)

我尝试通过按一个按钮将png图像从JavaScript传递到PHP页面。但是它返回一个错误,提示"请求URI太大"。以下是我的代码:

myJavaScript.js

1
2
3
4
                var w = window.open();
                var dom = w.document;
                var a = canvas[0].toDataURL("image/png");
                dom.write('< input type="button" value="Submit" onclick="location.href=\'result.php?a=' + a + '\'"></input>');

result.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
               <?php

                $aImg= $_GET["a"];

                $to ="[email protected]";
                $subject ="Sending an image to email";
                $body = '<img src="' .$aImg. '" alt="This is an image" />';
               if (mail($to, $subject, $body))
                              {  
                       echo("Message successfully sent!");  
                               }
                 else {  
                   echo("Message delivery failed...");
                      }  
              ?>

但是,它返回"请求的URL的长度超出了此服务器的容量限制。"


改为使用帖子。

1
dom.write('<form method="post" action="result.php"><input type="a" value="'+a+'" /><input type="submit" value="Submit" /></form>')

由于使用GET方法传递变量需要将变量放入URL中,因此对于大型变量,您将达到URL的最大长度。 POST没有限制,或者至少有一个更大的限制。


更改为使用POST代替GET,如果使用GET,则超出大数据的URL长度限制。