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 02 Answers
Reset to default 8Use 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.