首页 > 解决方案 > 我如何在另一个中显示另一个图像或文本

问题描述

我遇到了一些 PHP 问题。我想上传一张图片,显示它,点击“处理”后,在页面的另一边显示一些东西。例如代码,我只想显示“你好”。当我尝试这样做时,它会清除上传的图像。任何指向正确方向的指针?

非常感激。

代码:

<!DOCTYPE html
<html>
<head>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>


<body>
  
<div class="row">
<aside id="left">
    <form action="" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="file_to_upload" id="file_to_upload">
    <input type="submit" name="submits" id="upload_button" value="upload">
</form>

<div id="uploaded_pic">
<?php

if(isset($_POST['submits']))
{ 
$filepath = "images/upload" . $_FILES["file_to_upload"]["name"];

if(move_uploaded_file($_FILES["file_to_upload"]["tmp_name"], $filepath)) 
{
echo "<img src=".$filepath." height=640 width=480 />";
} 
else 
{
echo "Problem uploading";
}

} 
  
?>
</div>
<div id="process-button">
    <form action="" method="POST" name="processing">
    <input type="submit" name="process_button" id="process_button" value="process">
</form>
</div>

</aside>

<aside id="right">

<?php
    if (array_key_exists('process_button',$_POST))
    {
        echo "hello";
    }
?>
</div>
</aside>
</div>
</body>
</html>

标签: phphtml

解决方案


对于因类似问题或纯粹兴趣而担心的任何人-在此代码中,清除屏幕的问题是由第二种形式引起的。提交后就清屏了。所以我用一个简单的按钮和 onevent 处理程序替换了表单,现在它工作正常。


推荐阅读