0

我对php知之甚少,因此对任何愚蠢的错误感到抱歉。我在网上找到了这段代码,但不是我想要的。

如下所示,我正在显示一个表单,用户在其中写一些东西然后单击“CRIAR SELO”按钮,页面刷新,该文本被放到图像上并显示供他使用鼠标右键下载。

图 1

我希望当用户单击“CRIAR SELO”按钮时,会显示一个窗口,以便他可以选择在他的计算机中保存文件的位置,这样就无需右键单击并保存。

*我不需要一直显示图像,所以如果不能同时执行(显示和强制下载窗口)没有问题。

这是表格(index.php):

<?php $rda = isset($_GET['rda'])?$_GET['rda']:"00000BR"; ?>
<form action="" method="get" />
    <input name="rda" type="text" value="" placeholder="00000BR">
    <img src="selo.php?rda=<?php echo $rda ?>">
    <input type="submit" name="enviar" class="confirma" value="CRIAR SELO »">
</form>

这是 PHP (selo.php):

<?php
$imagem = imagecreatefromjpeg( "00000BR_01.jpg" );
$cor = imagecolorallocate( $imagem, 000, 000, 000 );
$font = "verdanab.ttf";
$rda = urldecode( $_GET['rda'] );
imagettftext($imagem, 20, 0, 37, 50, $cor, $font, $rda );
header('Content-type: image/jpeg');
imagejpeg( $imagem, '', 100 );
imagedestroy($imagem);
?>

谢谢您的帮助。

4

1 回答 1

0

I found a way.

I added a second button, so now the user clicks on "CRIAR SELO" to generate the image with his text and then clicks the button "DOWNLOAD" to download the generated image with the name of the text.

Ex: User types "77777BR", clicks "CRIAR SELO" and then "DOWNLOAD" to download a image called "7777BR.jpg".

<?php $rda = isset($_GET['rda'])?$_GET['rda']:"00000BR"; ?>
<form action="" method="get">
    <input name="rda" type="text" placeholder="00000BR">
    <br />
    <img src="selo.php?rda=<?php echo $rda ?>">
    <br />
    <input type="submit" name="enviar" class="confirma" value="CRIAR SELO »">
    <a href="selo.php?rda=<?php echo $rda ?>" download="<?php echo $rda.'.jpg' ?>">DOWNLOAD</a>
</form>
于 2017-03-15T13:27:05.123 回答