0

I tried to receive file name in controller, but can't. expect file, every peramter is getting received in controller. This is my jquery code with validation plugin.

$(document).ready(function () {
        $("#add_listing_form").validate({
            rules: {
                business_name: {required: true},
                logo_pic: {required: true},
                busi_type: {required: true},
                address: {required: true},
                about: {required: true}
            },
            highlight: function (element, errorClass) {
                $(element).css({borderColor: '#FF0000'});
            },
            unhighlight: function (element, errorClass, validClass) {
                $(element).css({borderColor: '#CCCCCC'});
            },
            submitHandler: function (form) {
                showprocess();
                $.ajax({
                    type: "POST",
                    url: "<?= base_url() ?>user/add_merchant",
                    data: $('#add_listing_form').serialize(),
                    dataType: 'json',
                    contentType: false,
                    cache: false,
                    processData: false,
                    success: function (data) {
                        removeprocess();
                        try {
                            var response = jQuery.parseJSON(data);
                            if (response.status == 'success') {                                     $('.status_msg').html(getSuccessHTML(response.msg));
                                windowRedirect(response.redirect, 1000);
                            } else {
                                $(' .status_msg').html(getErrorHTML(response.msg));
                            }
                        } catch (err) {
                       $(' .status_msg').html(getErrorHTML(AJAX_ERR));
                        }
                    }
                });
                return false;
            }
        });
    });

This is my HTML Code. I have put the entire code, so you can get the idea where i am stucked. I have tried different solution from stackoverflow and other sites.

<form id="add_listing_form" name="add_listing_form" class="form-horizontal" method="post" enctype="multipart/form-data">
                                <!-- Section -->
                                <div class="add-listing-section margin-top-45">
                                    <!-- Headline -->
                                    <div class="add-listing-headline">
                                        <h3><i class="sl sl-icon-plus"></i> Step 2: Add your Store Listing</h3>
                                    </div>
                                    <!-- Title -->
                                    <div class="row with-forms">
                                        <div class="col-md-12">
                                            <h5>Business Name</h5>
                                            <input type="text" name="business_name" id="business_name">
                                        </div>
                                        <div class="col-md-12">
                                            <h5>Logo</h5>
                                            <input type="file" class="storelogo" id="logo_pic" name="logo_pic">
                                        </div>
                                        <div class="col-md-12">
                                            <h5>Type of Business</h5>
                                            <select placeholder="Select a Category" class="chosen-select" id="business_type" name="business_type" >
                                                <?php
                                                foreach ($business_type as $row) {
                                                    echo "<option value=" . $row['id'] . ">" . $row['type'] . "</option>";
                                                }
                                                ?>
                                            </select>
                                        </div>
                                        <div class="col-md-12">
                                            <h5>Store Address</h5>
                                            <input id="autocomplete-input" type="text" name="address" id="address">
                                        </div>
                                        <div class="col-md-12">
                                            <h5>Hero Image</h5>
                                            <input type="file" id="hero_upload" name="hero_upload">
                                        </div>
                                        <div class="col-md-12">
                                            <h5>About</h5>
                                            <textarea name="about" id="about"></textarea>
                                        </div>
                                    </div>
                                    <div class="row with-forms">
                                        <!-- Phone -->
                                        <div class="col-md-4">
                                            <h5>Phone <span>(optional)</span></h5>
                                            <input type="text" name="phone" id="phone">
                                        </div>
                                        <!-- Website -->
                                        <div class="col-md-4">
                                            <h5>Website <span>(optional)</span></h5>
                                            <input type="text" name="website" id="website">
                                        </div>
                                        <!-- Email Address -->
                                        <div class="col-md-4">
                                            <h5>Public E-mail <span>(optional)</span></h5>
                                            <input type="text" name="pub_email" id="pub_email">
                                        </div>
                                    </div>

                                    <div class="row with-forms">

                                        <div class="col-md-6">
                                            <h5 class="fb-input"><i class="fa fa-facebook-square"></i> Facebook <span>(optional)</span></h5>
                                            <input type="text" placeholder="https://www.facebook.com/" name="fb_link" id="fb_link">
                                        </div>

                                        <div class="col-md-6">
                                            <h5 class="twitter-input"><i class="fa fa-twitter"></i> Twitter <span>(optional)</span></h5>
                                            <input type="text" placeholder="https://www.twitter.com/" name="tw_link" id="tw_link">
                                        </div>

                                        <div class="col-md-6">
                                            <h5 class="gplus-input"><i class="fa fa-google-plus"></i> Google Plus <span>(optional)</span></h5>
                                            <input type="text" placeholder="https://plus.google.com" name="g_link" id="g_link">
                                        </div>

                                        <div class="col-md-6">
                                            <h5 class="insta-input"><i class="fa fa-instagram"></i> Instagram <span>(optional)</span></h5>
                                            <input type="text" placeholder="https://plus.google.com" name="i_link" id="i_link">
                                        </div>

                                    </div>

                                </div>
                                <div class="status_msg"></div>
                                <!-- Section / End -->
                                <button type="submit" class="button preview pull-right">Submit <i class="fa fa-arrow-circle-right"></i></button>
                            </form>

This is my controller code. And i don't know what the problem is. But i receive the business name here but i don't get the file attributes.

  echo $_FILES["logo_pic"]["name"];
       $business_name = $this->input->post('business_name');
  echo $_FILES['logo_pic']['name'] ;

0 Answers0