简体   繁体   中英

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. I want the image was firstly send by ajaximage.php and shown and keept by another form and send to 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"> .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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