我不能完全肯定我理解了問題,但我認爲你可以做到這一點?如果表單只能在第一次提交表單後使用會話變量來控制表單是否顯示時才提交。您的代碼似乎表明,用戶可以輸入目的地userInput
和形式會使用,因爲它是行動〜所以畫面將永遠不會看到,除非用戶返回頁面〜在這種情況下會,如果他們需要一個會話變量是不是再次看到表格。
<?php
if($_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST['userInput'])){
/* Form has been submitted, show image */
include'img.php';
} else {/* open else condition */
?>
<form method='post'>
<input type='text' class='form-control input-lg' placeholder='Your Name?' name='userInput'>
<input type='submit' class='btn btn-primary btn-lg' name='submit' value='See Result'>
</form>
<?php
}/* close if/else condition */
?>
看到的圖像的例子或許下面可能幫助後?
<?php
session_start();
$field='userInput';
if($_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST[ $field ])){
$face=str_replace(' ', '_', urldecode(filter_input(INPUT_POST, $field, FILTER_SANITIZE_STRING)));
$_SESSION['face']=$face;
/* the url structure is setup in htaccess for my dev server, change to suit */
exit(header('Location: /face/'.$face));
}
?>
<!doctype html>
<html>
<head>
<title>Names and faces</title>
</head>
<body>
<?php
if($_SERVER['REQUEST_METHOD']=='GET' && empty($_GET[ $field ])){
?>
<form method='post'>
<input type='text' class='form-control input-lg' placeholder='Your Name?' name='userInput'>
<input type='submit' class='btn btn-primary btn-lg' name='submit' value='See Result'>
</form>
<?php
} else {
$face=filter_input(INPUT_GET, $field, FILTER_SANITIZE_STRING);
echo "<img src='/test/face-img.php' />";
}
?>
</body>
</html>
而且圖像生成器(img.php
):
<?php
session_start();
ini_set ('gd.jpeg_ignore_warning', 1);
if (error_reporting() === 0) return false;
/*
Directory containing various images from which
a random image will be selected.
Edit to suit your environment
*/
$dir = 'c:/wwwroot/images/css/tiles/';
/*
Location of a true type font on server
Edit to suit your environment.
*/
$font = 'c:/wwwroot/inc/fonts/arial.ttf';
/*
Find images of type `jpg` or `jpeg`
*/
$files = preg_grep('@(\.jpg$|\.jpeg$)@i', glob($dir . '*.*'));
/*
find a random file from those in directory
*/
$file = $files[ array_rand($files, 1) ];
/*
get properties of image
*/
list($w, $h, $t, $a) = getimagesize($file);
/*
Assign text from session variable
*/
$text=!empty($_SESSION['face']) ? str_replace('_', ' ', $_SESSION['face']) : 'whoops';
/*
fontsize and text angle
*/
$fontsize=25;
$angle=0;
/*
generate new image and overlay text with shadow
*/
$img = imagecreatefromjpeg($file);
$colour = @imagecolorallocate($img, 255, 255, 255);
$shadow = @imagecolorallocate($img, 0, 0, 0);
$box = @imagettfbbox($fontsize, $angle, $font, $text);
$offset=5;
$x = abs($box[0] + (imagesx($img)/2) - ($box[4]/2));
$y = abs($box[1] + (imagesy($img)/2) - ($box[5]/2));
imagettftext($img, $fontsize, $angle, $x+$offset, $y+$offset, $shadow, $font, $text);
imagettftext($img, $fontsize, $angle, $x, $y, $colour, $font, $text);
header('Content-type: image/jpeg');
imagejpeg($img);
imagedestroy($img);
?>
它不工作,請參閱該http://nametest.byethost9.com –
這是我的新的託管頁面 https://開頭naveenm106。 000webhostapp.com 我能有你的社交媒體鏈接連接到討論更多關於這一點,如果可能的感謝 –
我還沒有嘗試過,你出我與其他一些登錄就該好好輸出但仍我遇到了一些問題的方法@RamR急救人員 –