PHP图像上传问题

时间:2010-07-22 02:58:53

标签: php4

在下面的图片上传php代码中获取Undefined index:filename错误。以下代码有问题吗?

<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);
            }

1 个答案:

答案 0 :(得分:2)

将此添加到您的表单标记:

enctype="multipart/form-data" 

如果您正在进行文件上传,则需要此表单属性,以便Web服务器知道预期文件数据。有关文件上传的更多信息:http://www.tizag.com/phpT/fileupload.php