Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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."

like image 811
user1407415 Avatar asked Feb 11 '26 13:02

user1407415


2 Answers

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.

like image 191
Sean Johnson Avatar answered Feb 13 '26 09:02

Sean Johnson


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

like image 24
xdazz Avatar answered Feb 13 '26 10:02

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!