简体   繁体   English

我无法恢复文件发送给我它是空的“!empty($ _ FILES [”fileToUpload“] [”tmp_name“])”

[英]I can not recover the file send it to me that it is empty “ !empty ($ _ FILES [”fileToUpload“] [”tmp_name“])”

I would like to retrieve the send files from the page ad.php to the page index.php .我想从index.php ad.php I already tried several methods but the input is empty in the page index.php我已经尝试了几种方法,但是页面索引中的input为空index.php

I use the JS function setInterval to check that the input is not empty in annonce.php but when it is retrieved it becomes empty我使用JS function setInterval来检查annonce.php中的输入是否为空,但是当检索到它时它变为空

here are the two methods I use:这是我使用的两种方法:

! Empty ($ _ FILES [ "fileToUpload"] [ "tmp_name"])

$ check = getimagesize ($ _ FILES ["fileToUpload"] ["tmp_name"])

annonce.php annonce.php

            <div class="container">
                <div class="row">
                    <div class="col-md-2 col-xs-1" >
                        <img id="photoPrincipale" src="src/images/photoPrincipale.PNG",alt="photo principal" style="cursor:pointer">
                        <input name="fileToUpload" type="file"  id="fileToUpload" accept=".gif,.jpg,.jpeg,.png" style="display:none" onchange="uploadImage(this)"/>
                        <span id="supprimerPhotoPrincipale" style="cursor: pointer;display: none;color:red ;">Supprimer</span>

                    </div>
                    <div class="col-md-2 col-xs-1" >
                        <img id="photo2" src="src/images/photo.PNG",alt="photo" style="cursor:pointer">
                        <input name="file2ToUpload" type="file" id="file2ToUpload" accept=".gif,.jpg,.jpeg,.png" style="display:none" onchange="uploadImage2(this)"/>
                        <span id="supprimerPhoto2" style="cursor: pointer;display: none ;color:red ;">Supprimer</span>



                    </div>
                    <div class="col-md-2 col-xs-1" >
                        <img  id="photo3" src="src/images/photo.PNG",alt="photo" style="cursor:pointer">
                        <input name="file3ToUpload" type="file" id="file3ToUpload" accept=".gif,.jpg,.jpeg,.png" style="display:none" onchange="uploadImage3(this)"/>
                        <span id="supprimerPhoto3" style="cursor: pointer;display: none ;color:red ;">Supprimer</span>



                    </div>
                    <div class="col-md-2 col-xs-1" >
                        <img  id="photo4" src="src/images/photo.PNG",alt="photo" style="cursor:pointer">
                        <input name="file4ToUpload" type="file" id="file4ToUpload"  accept=".gif,.jpg,.jpeg,.png" style="display:none" onchange="uploadImage4(this)"/>
                        <span id="supprimerPhoto4" style="cursor: pointer;display: none ;color:red ;">Supprimer</span>



                    </div>
                    <div class="col-md-2 col-xs-1" >
                        <img  id="photo5" src="src/images/photo.PNG",alt="photo" style="cursor:pointer">
                        <input name="file5ToUpload" type="file" id="file5ToUpload" accept=".gif,.jpg,.jpeg,.png" style="display:none" onchange="uploadImage5(this)"/>
                        <span id="supprimerPhoto5" style="cursor: pointer;display: none">Supprimer</span>



                    </div>
                    </br>
                    <span id='messageIfSameImages' class="col-lg-12"></span>
                </div>

                </br>
                </br>

                <button name="submitAnnonce" type="submit" id="submitAnnonce" class="btn btn-primary col-lg-3" style="margin-left: 4px">Valider</button>

            </div>

    <?php $imageNames=array('fileToUpload','file2ToUpload','file3ToUpload','file4ToUpload','file5ToUpload');if(isset($_POST["submitAnnonce"])){
    for($i=0;$i<sizeof($imageNames);$i++){
        if(!empty($_FILES[$imageNames[$i]]["tmp_name"]))
        {
            ChromePhp::log('cette fichier et pas vide');

        }
    }}?>

index.php index.php

Please confirm you use multipart/form-data inside the form请确认您在form中使用multipart/form-data

<form action="/action_page_binary.php" method="post" enctype="multipart/form-data">

It's better to try this to check the file is empty or not.最好试试这个来检查文件是否为空。

if ($_FILES['fileToUpload']['size'] == 0 && $_FILES['fileToUpload']['error'] == 0)
{
    // cover_image is empty (and not an error)
}

You can check the file size which is in the $_FILES array.您可以检查$_FILES数组中的文件size

It's already defined in Check if the specified input file is empty已经在检查指定的输入文件是否为空中定义

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

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