If the file uploaded then send the file name or else send empty in the PHP - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, June 10, 2021

If the file uploaded then send the file name or else send empty in the PHP

I don't know I am doing my best or it will get issues in the future.

I have to display the 7 file type on my page and it will be increased in the future. So I have taken the array and store the label name and according to the label count, I am displaying the file type. So I have 7 labels in the array and I am getting 7 file types.

The below is the code I am using it.

<div class="input_fields_wrap">
      <?php
      $labelname = array('Label 1','Label 2','Label 3','Label 4','Label 5','Label 6','Label 7');
      $labelCount=count($labelname);
        ?>
   <div class="row mt-3">
      <?php 
      for ($i=0; $i < $labelCount; $i++) { 
       ?>
       <div class="col-lg-4 mb-4 ">
         <div class="documentUploadWrap">
            <label><?php echo $labelname[$i];?></label>

         <div class="upload_doc">
          <input type="hidden" name="docUploadLabel[]" value="<?php echo $labelname[$i];?>">
          <input type="file" name="docUpload[]"  class="fileupload">
          <input type="hidden" name="docUpload[]" value="">

          <div class="uploadInfo">
             <div class="upload_icon"></div>
             <p>Drop your image here, or <span>browse</span></p> 
             <span>Supports: JPEG, PNG, PPT, PPTX, PDF <br />Max Size: 5MB</span>
          </div>
       </div>
         </div>
      </div> 
    <?php } ?>

Now, I uploaded the file in the first two file type, and the rest 5 are empty. Then I hit the submit button and I am getting below error.

1) enter image description here

2) Notice here If I upload 1 or 2 files the second name continues repeating till 7 iterations.

enter image description here



source https://stackoverflow.com/questions/67910198/if-the-file-uploaded-then-send-the-file-name-or-else-send-empty-in-the-php

No comments:

Post a Comment