我现在正在构建一个元素,它有一些错误,我找不到它们,所以请帮助我。 我已经创建了一个 html 文件名 (name.html) 和一个 php 文件名 (result.php) 当我们点击提交按钮时我添加了一些 Java 它将带我们到 result.php 并在图像上显示文本通过 php 我的编码是这样的。
对于 (name.html)
<html>
<body>
<input type="text" id="name" name="myname" placeholder="E.g: abc">
<input type="button" id="next" name="submit">
</body>
</html>
对于(结果.php)
<? php
header("Content-type: image/jpeg");
$imgPath = 'image.jpg';
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 255, 255, 255);
$string = $_GET["name"];
$fontSize = 3;
$x = 115;
$y = 185;
imagestring($image, $fontSize, $x, $y, $string, $color);
imagejpeg($image);
?>
问题是,当我点击提交按钮时,脚本将我带到页面 result.php 并且未显示 Input 标签内的文本。
最佳答案
这是工作的例子
名称.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="result.php" method="get">
<input type="text" id="name" name="myname" placeholder="E.g: abc">
<input type="submit" value="Submit">
</form>
</body>
</html>
结果.php
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(300, 100);
$text_color = imagecolorallocate($im, 233, 14, 91);
$string = $_GET["myname"];
imagestring($im, 20, 5, 5, $string, $text_color);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($im);
// Free up memory
imagedestroy($im);
?>
关于javascript - 如何将 html 标签 id 转换为 php 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29580780/