【问题标题】:How to send image value from form to another page?如何将图像值从表单发送到另一个页面?
【发布时间】:2012-12-27 16:18:25
【问题描述】:

我正在处理一个项目,其中用户填写了一个表单,并且该值显示在另一个页面中。我在另一个页面中获得的所有数据但图像无法在该页面上显示,仅显示图像名称。我想显示图像,我该怎么做?

第1页

<form action="save.php" class="contact-form" method="post" name="inputname">
<table>
<tr>
<td class="label">Name:</td>
<td><input type="text" class="input-text" name="pname" /></td>
</tr>
<tr>
<td class="label">City:</td>
<td><input type="text" class="input-text" name="pcity" /></td>
</tr>
<tr>
<td class="label">Country:</td>
<td><input type="text" class="input-text" name="pcountry" /></td>
</tr>
<tr>
<td class="label">Email:</td>
@ 987654337@
</tr>
<tr>
<td class="label">Upload Your Photo:</td>
<td><input type="file" accept="image/jpg,image/gif" class="input-text" name="pphoto"/></td>
</tr>

第 2 页 save.php

mysql_connect("localhost","root","");
mysql_select_db("my_db");
$p_name=$_POST['pname'];              
$p_city=$_POST['pcity'];
$p_country=$_POST['pcountry'];
$p_email=$_POST['pemail'];
$p_photo=$_POST['pphoto'];


<table>  
<ul>  
<tr>  
<td><li class="image"><img src="<? echo $p_photo; ?>" /></li></td>  
<li class="text">  
<td class="label">  
Name: <? echo $p_name; ?></br>    
City: <? echo $p_city; ?></br>  
Country: <? echo $p_country; ?></br>  
E-Mail: <? echo $p_email; ?></br>  
</td>  
</li>  
</tr>  
</ul>
</table>

【问题讨论】:

  • 为此使用 Get 或 Post....
  • 很高兴看到主窗体的布局。

标签: php html mysql


【解决方案1】:

如果您将图像作为文件上传,那么您应该使用 $_FILES 数组。你应该先保存上传的图片。

【讨论】:

  • 如果图片来自 URL 怎么办?在我们知道主页上的图像是如何处理的之前,我们无法真正给出具体的答案。
  • 如果来自 URL 的图像,那么一切都应该工作并且 TS 没有发布这个问题 :)
【解决方案2】:
@$file = fopen($_FILES['file'] ['tmp_name'], "r");
@$image = addslashes(fread($file, filesize($_FILES['file']['tmp_name'])));

使用您的文件名而不是“文件”。

【讨论】:

    猜你喜欢
    • 2012-09-17
    • 2017-05-22
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    相关资源
    最近更新 更多