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."
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With