繁体   English   中英

将一个文件发送到两个输入

[英]Sending one file to two inputs

我有一个小问题,我解决不了。 下面是我的表格。 问题是:我怎样才能将输入内容在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>

您不能将文件从一个<input type="file">到另一个<input type="file">

这是因为出于安全原因,您无法设置文件输入值。

您无法将上传的文件直接传递到其他表单。 您需要将其移动到临时位置并为其提供唯一的文件名,然后可以将其存储到第二种形式的隐藏字段中。 当您提交第二个表单时,您将收到隐藏的值,然后便可以访问先前上传的文件。

看到这个: http : //php.net/manual/en/function.move-uploaded-file.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM