最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

I try to pass a png image from JavaScript to PHP page by pressing a button. But it returns me an error stating "Request-URI Too Large". Below is my codes:

myJavaScript.js

                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

               <?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...");
                      }  
              ?>

However, it returns "The requested URL's length exceeds the capacity limit for this server."

I try to pass a png image from JavaScript to PHP page by pressing a button. But it returns me an error stating "Request-URI Too Large". Below is my codes:

myJavaScript.js

                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

               <?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...");
                      }  
              ?>

However, it returns "The requested URL's length exceeds the capacity limit for this server."

Share Improve this question asked Jun 25, 2012 at 5:57 user1407415user1407415 1091 silver badge8 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

Use post instead.

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

Because passing variables using the GET method require putting the variables in the URL, you will hit the maximum length of a URL for large variables. POST does not have a limit, or at least has a much larger one.

Change to use POST instead of GET, if you use GET, the URL length limit be exceeded for big data.

发布评论

评论列表(0)

  1. 暂无评论