使用iframe的target属性将表单发布到php脚本
我正在从事一个php/HTMLWeb项目,我有一个表单,其中包含一个输入类型文件,该文件应该发布到php脚本中,以便将图像上传到服务器上。在form标记中,我使用target属性将iframe作为目标,这样它就可以模拟AJAX风格的post,也就是说,它将post发送到iframe,这样iframe就可以在不需要刷新主页的情况下完成工作 下面是我正在使用的表单使用iframe的target属性将表单发布到php脚本,php,html,forms,iframe,Php,Html,Forms,Iframe,我正在从事一个php/HTMLWeb项目,我有一个表单,其中包含一个输入类型文件,该文件应该发布到php脚本中,以便将图像上传到服务器上。在form标记中,我使用target属性将iframe作为目标,这样它就可以模拟AJAX风格的post,也就是说,它将post发送到iframe,这样iframe就可以在不需要刷新主页的情况下完成工作 下面是我正在使用的表单 <form method="post" action="phpHandler/image-uploader.php" ta
<form method="post" action="phpHandler/image-uploader.php" target="image_upload_frame">
<table>
<tr>
<td>
Image Title:
</td>
<td>
<input type="text" id="txtImageTitle" name="txtImageTitle" />
</td>
</tr>
<tr>
<td>
Image File:
</td>
<td>
<input type="file" id="txtImageFile" name="txtImageFile" />
</td>
</tr>
</table>
正在执行PHP脚本,但$\u文件和$\u POST数组为空
我尝试更改iframe以包含指向php脚本的src属性,并从表单中删除了该操作,但这似乎甚至没有执行php脚本
谢谢你能提供的帮助 添加
enctype="multipart/form-data"
到
加
到
谢谢,真不敢相信我忘了。谢谢,真不敢相信我忘了。
echo "posting";
$title = $_POST['txtImageTitle'];
$tempName = $_FILES['txtImageFile']['name'];
writeToLog("Image Title:" . $title);
writeToLog("Temp Name: $tempName\n");
$data = var_export($_POST, true);
$fileData = var_export($_FILES, true);
writeToLog($data);
writeToLog($fileData);
function writeToLog($message)
{
$fh = fopen('log.txt', 'a');
fwrite($fh, $message);
fclose($fh);
}
enctype="multipart/form-data"
<form method="post" action="phpHandler/image-uploader.php" target="image_upload_frame">