我完全靠在墙上。我一直在尝试从教程中学习PHP,将两个表单输入输出到我的函数以生成图像。
我已经解决了我混合使用POST和GET的问题,但现在我的脚本根本无法运行,我无法理解为什么 - 我确定这对于任何开发者来说都是有用的我有点过头了。
这是我的app.php
This is what i have now in my page-name.php
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null, // any parent
'post_mime_type' => 'image'
);
$attachments = get_posts($args);
if ($attachments) {
$attachment_meta = wp_get_attachment($attachment->ID);
foreach ($attachments as $post) {
if ($attachment_meta['caption'] == 'Ceahlau' ){
setup_postdata($post);
echo wp_get_attachment_image( $attachment->ID, 'full' );
the_attachment_link($post->ID, false);
}
}
}
?>
调用pngfile.php
<?php
if (isset($_POST['submit'])) {
$data = $_POST['name']; // the data from text input.
$colour = $_POST['colour']; // data from colour radio.
}
?>
...
<form action="/app.php" method="post">
<input type="text" name="name"/>
<input name="colour" type="radio" value="1">Red<br>
<input name="colour" type="radio" value="2">Blue<br>
<input name="colour" type="radio" value="3">Green<br>
<input type="submit" name="submit" value="Submit">
</form>
<img src="pngfile.php?data=<?php print $data;?>" alt="">
反过来调用functions.php
<?php
require_once 'functions.php'; // Requires and includes do not need brackets.
$textdata = $_POST['data'];
$colourdata = $_POST['colour'];
process($textdata,$colourdata);
exit;
?>
所有这一切都在以前完美运行,但我添加的唯一更改是更新所有元素以使用POST,并在三个文件中添加代码以添加所选颜色以发布。但是使用这个调整过的代码,我得不到图像输出,即使我知道我的主图像功能正常,所以它必须是我的app.php和pngfile.php错误。
有人可以给我一些关于我哪里出错的指导吗?
答案 0 :(得分:1)
你的问题是你要发送这个:
<img src="pngfile.php?data=<?php print $data;?>" alt="">
但您的代码正在寻找:
$textdata = $_POST['data'];
$colourdata = $_POST['colour'];
没有帖子,肯定没有$_POST['colour']
。但是有一个$_GET['data']
;我认为这就是你要找的东西。作为URL的一部分传递的数据是GET请求的一部分,可在$_GET
中使用。 $_POST
用于通过POST请求发送的数据。