PHP图片上传问题

发布于 2024-09-10 17:38:54 字数 3992 浏览 5 评论 0原文

在下面的图像上传 php 代码中出现未定义的索引:文件名错误。下面的代码有问题吗?

<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>

添加业务详细信息控制器

    function addbusinessdetail()
            {
              print_r($_FILES['filename']);
              $this->Admin->addbusinessdetail();
              $this->businessdetails(0,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);
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-09-17 17:38:54

将其添加到您的表单标记中:

enctype="multipart/form-data" 

如果您要进行文件上传,则需要此表单属性,以便网络服务器知道需要文件数据。以下是有关文件上传的更多信息: tizag.com/phpT/fileupload.php" rel="nofollow noreferrer">http://www.tizag.com/phpT/fileupload.php

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文