【问题标题】:create an image and dialog box on same screen in php在php中的同一屏幕上创建图像和对话框
【发布时间】:2019-12-26 13:50:35
【问题描述】:

我正在尝试在 php.ini 的一个屏幕上同时创建一个图像和一个对话框。我最终希望对话框能够控制图像(例如在图像上显示更多线条)。当我运行代码时,它只显示图像,而不是对话框。我必须缺少一些额外的代码才能使其工作。请帮忙。谢谢你的任何建议。

<?php
    header('Content-type: image/png');
    $png_image = imagecreate(50, 50); 
    imagecolorallocate($png_image, 15, 142, 210);
    $black = imagecolorallocate($png_image, 0, 0, 0);
    imageline($png_image, 0, 0, 50, 50, $black);  
    imagepng($png_image);
    imagedestroy($png_image);   
?>

<html>
    <form action="" method="post">
        Name:<input type="text" id="name" name="name"/>
        <input type="submit" value="submit" name="submit"/>
    </form>
</html>

【问题讨论】:

    标签: php html image dialog


    【解决方案1】:

    您不能在 php.ini 中在屏幕上创建任何内容。它只生成文件。您可以使用 php 脚本来生成图像。我们称之为img.php

    <?php
        header('Content-type: image/png');
        $png_image = imagecreate(50, 50); 
        imagecolorallocate($png_image, 15, 142, 210);
        $black = imagecolorallocate($png_image, 0, 0, 0);
        imageline($png_image, 0, 0, 50, 50, $black);  
        imagepng($png_image);
        imagedestroy($png_image);   
    ?>
    

    您可以使用另一个.html.php 文件来生成包含该图像的html 代码:

    <html>
      This is the image:
      <img src="img.php">
    </html>
    

    如果要根据用户操作重新创建图像,则必须在 html 代码中包含一些 JavaScript,这将强制重新加载图像。

    【讨论】:

    • 那行得通@AterLux,我在同一个文件夹中创建了两个不同的文件,程序运行正常,我将研究更多关于根据用户操作重新创建的 JavaScript。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多