简体   繁体   English

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

[英]Sending one file to two inputs

I have a little problem and i cant solve it. 我有一个小问题,我解决不了。 Below is my form. 下面是我的表格。 The question is: how can i put image which was put in input where is ajaximage.php to another form to a hidden input. 问题是:我怎样才能将输入内容在ajaximage.php中的图像放入另一种形式的隐藏输入中。 I want the image was firstly send by ajaximage.php and shown and keept by another form and send to upload.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>

You can't add a file from one <input type="file"> to another <input type="file"> . 您不能将文件从一个<input type="file">到另一个<input type="file">

This is because you can't set a file inputs value due to security reasons. 这是因为出于安全原因,您无法设置文件输入值。

You cannot pass uploaded files directly to another form. 您无法将上传的文件直接传递到其他表单。 You need to move it into a temporary location and give it a unique filename which you can then store into a hidden field in the second form. 您需要将其移动到临时位置并为其提供唯一的文件名,然后可以将其存储到第二种形式的隐藏字段中。 When you submit the second form then you receive the hidden value and you are then able to access the previously uploaded file. 当您提交第二个表单时,您将收到隐藏的值,然后便可以访问先前上传的文件。

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

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

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