我有一点问题,我无法解决它。以下是我的表格。问题是:我怎样才能将放入输入的图像ajaximage.php放到另一个形式的隐藏输入中。我希望图像首先由ajaximage.php发送并显示并保存为另一个表单并发送到upload.php
<div class="kontakt">
<input type="checkbox" name="check" value="1" onclick="document.getElementById('imgfile').style.display = this.checked ? 'block' : 'none';
this.elements['photoimg'].disabled = this.form.elements['nazwa3'].disabled = !this.checked" />
<form id="imageform" name="nazwa2" disabled="disabled"style="display: none" method="post" enctype="multipart/form-data" action='ajaximage.php'>
<input id="imgfile" style="display: none" type="file" name="photoimg" id="photoimg" />
<div id='preview'></div>
</form>
<form id="dodaj" method="POST" enctype="multipart/form-data" action="upload.php">
<input type="hidden" name="ok" value="1">
<input type="hidden" name="MAX_FILE_SIZE" value="665600">
<input type="file" style="margin-bottom:30px; margin-top:20px;" name="plik" size="40" />
<textarea rows="4" cols="50" style="margin-bottom:30px;" placeholder="Wpisz swój tekst." required name="tekst" wrap="virtual">
<?php
if(isset($_SESSION['tekst']))
{
$tekst = $_SESSION['tekst'];
echo $tekst;
}
?>
</textarea>
<input type="submit" value="Dodaj" />
</form>
</div>
答案 0 :(得分:2)
您无法将文件从<input type="file">
添加到另一个<input type="file">
。
这是因为出于安全原因,您无法设置文件输入值。
答案 1 :(得分:2)
您无法将上传的文件直接传递到其他表单。您需要将其移动到临时位置并为其提供唯一的文件名,然后您可以将其存储到第二种形式的隐藏字段中。当您提交第二个表单时,您会收到隐藏的值,然后您就可以访问以前上传的文件。
请参阅:http://php.net/manual/en/function.move-uploaded-file.php