从5.2.17升级到版本5.4.24后PHP中的异常

时间:2014-01-29 11:19:04

标签: php html error-handling

嘿伙伴stackoverflow成员,

我几天来一直在努力解决这个问题,似乎无法解决这个问题。

我的问题:

PHP Notice: Undefined index: use_default in settings.php on line 111

这是向我抛出的错误/异常,但在多次尝试修复此问题之后,我只是无法让它完全正常工作。我刚刚从5.2.17升级到PHP版本5.4.24,这就是为什么这个错误被抛向我的原因。当使用旧的PHP版本时,这个例外永远不会出现。

无论如何,这就是我在settings.php中的第111行:

if (isset($_FILES['myfile']) && !empty($_FILES['myfile']['name']) && $_POST['use_default'] != 'on') {

它的整个部分(更新):

 if(empty($errors) === true) {

                        if (isset($_FILES['myfile']) && !empty($_FILES['myfile']['name']) && $_POST['use_default'] != 'on') {

                        $newpath = $general->file_newpath($path, $name);

                            move_uploaded_file($tmp_name, $newpath);

                        } else if(isset($_POST['use_default']) && $_POST['use_default'] === 'on') {
                                    $newpath = 'avatars/default_avatar_mc.png';
                                    }

                        $clan_tag           = htmlentities(trim($_POST['clan_tag']), ENT_QUOTES, "UTF-8"); // ENT_QUOTES - (review, may need revised)
                        $gamer_tag          = htmlentities(trim($_POST['gamer_tag']), ENT_QUOTES, "UTF-8"); // ENT_QUOTES - (review, may need revised)
                        $gender             = htmlentities(trim($_POST['gender']));
                        $day                = htmlentities(trim($_POST['day']));
                        $month              = htmlentities(trim($_POST['month']));
                        $year               = htmlentities(trim($_POST['year']));
                        $country            = htmlentities(trim($_POST['country']));
                        $occupation         = htmlentities(stripslashes($_POST['occupation']));
                        $interests          = htmlentities(stripslashes($_POST['interests']));
                        $bio                = htmlentities(stripslashes($_POST['bio']));
                        $status             = htmlentities(stripslashes($_POST['status']));
                        $xfire              = htmlentities(trim($_POST['xfire']));
                        $steam              = htmlentities(trim($_POST['steam']));
                        $image_location         = htmlentities(trim($newpath));

                        $users->update_user(    $clan_tag,
                                    $gamer_tag,
                                    $gender,
                                    $day,
                                    $month,
                                    $year,
                                    $country,
                                    $occupation,
                                    $interests,
                                    $bio,
                                    $status,
                                    $xfire,
                                    $steam,
                                    $image_location,
                                    $user_id);
                                    header('Location: settings.php?success');
                                    exit();

                    } else if (empty($errors) === false) {
                        echo '<p>' . implode('</p><p>', $errors) . '</p>';
                    }

然后是最后一点:

<input type="checkbox" name="use_default" id="use_default" /> <label for="use_default">Use default picture</label>

如果用户上传新的图片,我只收到此异常错误, - 我们将非常感谢任何帮助......

1 个答案:

答案 0 :(得分:0)

在执行此行之前

if (isset($_FILES['myfile']) && !empty($_FILES['myfile']['name']) && $_POST['use_default'] != 'on') {

isset上执行 use_default ..就像这样。

if(isset($_POST['use_default']))
{
 if (isset($_FILES['myfile']) && !empty($_FILES['myfile']['name']) && $_POST['use_default'] != 'on') {