0

I am facing one issue. I am getting the blank value of file input after submitting the form using PHP. I am explaining my code below.

<form action="" method="POST" enctype="multipart/form-data">
  <div class="row form-group">
              <label  class="col-md-3 control-label text-left">Icon</label>
              <div class="col-md-8 image-upload">
                <label for="vcicon">
                  <img src="<?php if($ts->sett_img==''){ echo PT_TOURS_SLIDER_THUMB_UPLOAD.'blank.jpg'; }else{ echo $ts->sett_img; } ?>" style="cursor:pointer;width:auto; height:160px; border:1px #666 solid" id="preview_imgedit"/>
                </label>
                <input type="file" id="vciconedit" name="vciconedit" accept="image/*"/>
                <div class="input-group bmargindiv1 col-md-12">
                    <label for="vcicon" >
                      <span style="color:#00F; font-style:italic; cursor:pointer"> Click here to upload Icon </span>
                      <input type="hidden" name="someIconedit" id="someIconedit" value="<?php echo $ts->sett_img; ?>" />
                    </label>
                </div>
              </div>
            </div>
</form>

The above part is my HTML form and the JavaScript part is given below.

$('#vciconedit').change(function(){
      readImageData(this);
    })
    function readImageData(imgData){
      if (imgData.files && imgData.files[0]) {
        var readerObj = new FileReader();
        readerObj.onload = function (element) {
          $('#preview_imgedit').attr('src', element.target.result);
          $('#someIconedit').val('');
        } 
        readerObj.readAsDataURL(imgData.files[0]);
      }
    }


<?php 

 print_r($_FILES);exit;

?>

When I am printing the file value after submit it giving the value like below.

Array ( [vciconedit] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )

Here I need to get all value from above array after submitting the form.

episch
  • 388
  • 2
  • 19
  • Are you sure, that you upload a file -> the error code 4 says: UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded. i think your problem ist not the PHP code, more your fancy piece of js ;) – episch Nov 09 '18 at 10:45
  • @episch : How it can be resolved ? –  Nov 09 '18 at 10:48
  • your js have to be easier like: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fileupload_get and then you post the file information to the PHP file ! Or use the search: https://stackoverflow.com/questions/18698325/upload-a-file-using-php-and-javascript – episch Nov 09 '18 at 10:50

0 Answers0