0

Getting Undefined index: filename error in the below image upload php code. Is there any problem in the below code?

<div id="content">
    <form class="wufoo" action=<?php echo (BASE_PATH. 'admin/addbusinessdetail'); ?> method="post">
            <input type="hidden" name="maxSize" value="9999999999" />
            <input type="hidden" name="maxW" value="200" />
            <input type="hidden" name="fullPath" value="<?php echo (BASE_PATH. 'public/img/uploads/'); ?>" />
            <input type="hidden" name="relPath" value="<?php echo (BASE_PATH. 'public/img/uploads/'); ?>" />
            <input type="hidden" name="colorR" value="255" />
            <input type="hidden" name="colorG" value="255" />
            <input type="hidden" name="colorB" value="255" />
            <input type="hidden" name="maxH" value="300" />           
        <ul>
             <li>
        <label class="desc">Business Type</label>
            <br />
                    <div>
                        <select class="field select" name="ddltype" style="width:300px; height: 30px;">
                            <?php
                                $types = $this->_data;
                                foreach ($types as  $value) {
                                   foreach($value as $innvalue){
                                         $businessname[] = $innvalue;
                                        }
                                        echo('<option value="'.$businessname[0].'">'.$businessname[1].'</option>');
                                        unset($businessname);
                                }
                            ?>
                        </select>
                    </div>
        </li>
        <li>
        <label class="desc">Business Detail <span class="req">*</span></label>
                    <br />
            <div>
                        <input type="text" class="field text" name="businessname" style="width: 300px; height: 20px;" />
            </div>
        </li>
            <li>
        <label class="desc">Business Website <span class="req">*</span></label>
                    <br />
            <div>
                        <input type="text" class="field text" name="website" style="width: 300px; height: 20px;" />
            </div>
        </li>
            <li>
        <label class="desc">Business Email <span class="req">*</span></label>
                    <br />
            <div>
                        <input type="text" class="field text" name="email" style="width: 300px; height: 20px;" />
            </div>
        </li>
            <li>
        <label class="desc">Business Image <span class="req">*</span></label>
                    <br />
            <div>
                        <input type="file" name="filename" />
            </div>
        </li>
            <li>
        <label class="desc">Address <span class="req">*</span></label>
                    <br />
            <div>
                        <textarea name="address" cols="50" rows="8" ></textarea>
            </div>
        </li>
        <li class="buttons">
            <input class="submit" type="submit" value="Save" /> <input class="submit" type="button" value="Cancel" onClick="history.back()" />
        </li>
        </ul>

    </form>

addbusinessdetail controller

    function addbusinessdetail()
            {
              print_r($_FILES['filename']);
              $this->Admin->addbusinessdetail();
              $this->businessdetails(0,0);
            }
2
  • Getting Undefined index: filename error in the below image upload php code. Is there any problem in the below code? Commented Jul 22, 2010 at 3:04
  • is your form multipart/form-data ?... please past the <form> tag and it's content... Also, i will always do a if (isset()) evaluation before calling the array... [edited] Oops, when added this comment the correct code wasn't in the question.. Commented Jul 22, 2010 at 3:06

1 Answer 1

2

add this to your form tag:

enctype="multipart/form-data" 

If you're doing a file upload, you need this form attribute so the web server knows to expect file data.Here's some more info on file uploads: http://www.tizag.com/phpT/fileupload.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.