我注意到未定义索引,但索引就在那里

时间:2014-11-27 13:26:25

标签: php

我一直在Notice:Undefined index: upFile in /home/hostnile/public_html/v2/ar/includes/content/career.php on line 93

这就是第93行$myCv = $_FILES['upFile']['name'];

中的内容
<div class="cointainer">
    <label for="upFile" class="f_right  width_165">upload file</label>
    <input type="file" name="upFile" id="upFile" class="f_right" style="direction:rtl;"/>
</div>

我在这里做错了什么? 怎么解决这个?

修改

HTML完整代码

<div class="bgPages">
            <div class="contentPages">
                <div class="width_818 career">
                    <div class="header"><span>يشرفنا دائما أن ينضم إلى فريق عملنا باحثون جدد عن الأفضل</span></div>

                    <form id="apply career" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                        <div class="body">
                            <?php
                            //handling message2
                            if ($msg == "done") {
                                echo "<div class='fontGreen'> نشكرك علي حرصك الانضمام لفريق عملنا</div>";
                            } elseif ($msg == "fail") {
                                echo "<div class='fontRed'> لم تصل رسالتك برجاء المحاولة مرة اخري</div>";
                            }
                            ?>
                            <div class="cointainer margin_16px">
                                <label for="yourName" class="f_right  width_165">الاسم</label>
                                <input name="yourName" id="yourName" type="text" class="form_textarea_rec"/>
                            </div>

                            <div class="cointainer">
                                <label for="yourEmail" class="f_right  width_165"> بريدك الالكتروني</label>
                                <input type="text" name="yourEmail" id="yourEmail" class="form_textarea_rec"/>
                            </div>

                            <div class="cointainer">
                                <label for="yourJob" class="f_right  width_165">الوظيفة</label>
                                <input type="text" name="yourJob" id="yourJob" class="form_textarea_rec"/>
                            </div>

                            <div class="cointainer">
                                <label for="yourTele" class="f_right  width_165">رقم التليفون</label>
                                <input type="text" name="yourTele" id="yourTele" class="form_textarea_rec"/>
                            </div>

                            <div class="cointainer">
                                <label for="upFile" class="f_right  width_165">تحميل السيرة الذاتية </label>
                                <input type="file" name="upFile" id="upFile" class="f_right" style="direction:rtl;"/>
                            </div>

                            <div class="f_right m_top_10px">
                                <p class="f_right width_165">أدخل كود التحقق</p>
                                <input class="form_textarea_cap f_right" type="text" name="captcha" id="captcha">
                                <img src="includes/content/captcha.php"
                                     style="margin-top: 3px; height: 30px; float: right"/>
                                <?php
                                //handling message1
                                if ($msg == "ec") {
                                    echo "<img src='../images/error.png' width='34' height='34' alt='' class='margin_8r f_right'/>";
                                }
                                ?>
                            </div>

                        </div>
                        <div class="footer"><input type="submit" value="ارسل" class="s_btn" name="submit" id="submit"/>
                        </div>
                    </form>
                </div>

            </div>


        </div>

这是完整的PHP代码

<?php
/**
 * Created by PhpStorm.
 * User: Yousef
 * Date: 6/15/14
 * Time: 3:29 PM
 */
error_reporting(E_ALL | E_STRICT);
if (isset($_POST['submit'])) {
    session_start();
    $yourName = $_POST['yourName'];
    $yourEmail = $_POST['yourEmail'];
    $yourJob = $_POST['yourJob'];
    $yourTele = $_POST['yourTele'];
    $myCv = $_FILES['upFile']['name'];
    $captcha = $_POST['captcha'];

    if (isset($_POST["captcha"]) && $_POST["captcha"] != "" && $_SESSION["code"] == $_POST["captcha"]) {
        $strTo = 'johnef_sh@hotmail.com';
        $strSubject = "Someone apply for career";
        $strMessage = nl2br("This information is for someone who apply for your new career\r\n
    Position Applied For:" . $yourJob . ",\r\n
    His Name Is: " . $yourName . ",\r\n
    His Phone Number: " . $yourTele . ",\r\n
    His Email: " . $yourEmail . " \r\n");

//*** Uniqid Session ***//
        $strSid = md5(uniqid(time()));
        $strHeader = "";
        $strHeader .= "From:johnef_sh@hotmail.com\r\nReply-To:johnef_sh@hotmail.com";
        $strHeader .= "MIME-Version: 1.0\n";
        $strHeader .= "Content-Type: multipart/mixed; boundary=\"" . $strSid . "\"\n\n";
        $strHeader .= "This is a multi-part message in MIME format.\n";
        $strHeader .= "--" . $strSid . "\n";
        $strHeader .= "Content-type: text/html; charset=utf-8\n";
        $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
        $strHeader .= $strMessage . "\n\n";

//*** Attachment ***//
        if ($_FILES['upFile']['name'] != "") {
            $strFilesName = $_FILES["upFile"]["name"];
            $strContent = chunk_split(base64_encode(file_get_contents($_FILES["upFile"]["tmp_name"])));
            $strHeader .= "--" . $strSid . "\n";
            $strHeader .= "Content-Type: application/octet-stream; name=\"" . $strFilesName . "\"\n";
            $strHeader .= "Content-Transfer-Encoding: base64\n";
            $strHeader .= "Content-Disposition: attachment; filename=\"" . $strFilesName . "\"\n\n";
            $strHeader .= $strContent . "\n\n";
        }


        $flgSend = @mail($strTo, $strSubject, null, $strHeader); // @ = No Show Error //

        if ($flgSend) {
            header("Location:?pid=11&msg=done");
        } else {
            //header('Location:?pid=11&msg=fail');
        }
    } else {
        header("Location:?pid=11&msg=ec");
    }
}
?>

1 个答案:

答案 0 :(得分:0)

您错过了enctype="multipart/form-data"。添加到表单 -

<form id="apply career" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">