上传文件在此页面中无效

时间:2014-08-22 09:19:13

标签: php

它保存数据中的所有内容,但不保存更新文件的名称。它显示了17,18,19,20行中未定义的索引,它没有显示数据库中的PIC列中的任何内容。没有任何内容存储在subjects_pic文件夹中。

此处显示代码:

<?php
include('conect.php');
$d = '';
$qre = mysql_query("select * from courses1");
while ($res = mysql_fetch_array($qre)) {
    $d .='<option value="' . $res['cid'] . '">' . $res['cname'] . '</option>';
}
?>
<?php
include('auth.php');
include('conect.php');
$msg = '';
if (isset($_POST['save'])) {
    $course = $_POST['courses1'];
    $subjects = $_POST['subjects'];
    $name = $_POST['name'];
    $file_name = $_FILES['f1']['name'];
    $file_type = $_FILES['f1']['type'];
    $file_size = $_FILES['f1']['size'];
    $file_tmp = $_FILES['f1']['tmp_name'];
    $file_path = '../subject_pic/' . $file_name;
    move_uploaded_file($file_tmp, $file_path);
    mysql_query("INSERT INTO up_file (cid,subid,name,pic) 
    VALUES ('$course','$subjects','$name','$file_name')");

    $msg = '<h3>Record Saved</h3>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>subjects</title>
        <link rel="stylesheet" type="text/css" href="headerstyle.css" />
        <script type="application/javascript" src="prototype.js"></script>
        <script type="text/javascript">
            function abc()
            {
                var a = $('courses1').value;
                $("k").innerHTML = '<img src="ajax-loader.gif">';
                new Ajax.Request("ajax1.php", {
                    method: 'post',
                    postBody: "e=" + a,
                    onComplete: Update_abc
                });

            }
            function Update_abc(req)
            {
                var data = req.responseText;
                $("k").innerHTML = '';
                $("k").innerHTML = data;
                //alert(data);

            }

        </script>
    </head>

    <body>
        07/25/2014
        <div class="fixx"><?php include('header.php'); ?></div>
        <div class="tabl">
            <table width="700" border="0">

                <tr>
                    <td>
                        <form method="post" action="filupload.php">
                            <table width="700" border="1" cellpadding="10">
                                <tr>
                                    <td colspan="2"><h3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ADD Files To Subjects &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="fil_list.php"> EDIT</a> </h3></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><?php echo $msg; ?></td>
                                </tr>
                                <tr>
                                    <td width="174"><h4>Select Course </h4></td>
                                    <td width="674"><label for="courses"></label>
                                        <select name="courses1" id="courses1" onchange="abc()">
                                            <option value="">Select Course</option>
                                            <?php echo $d; ?>
                                        </select>         </td>
                                </tr>
                                <tr>
                                    <td width="174"><h4>Select Subject </h4></td>
                                    <td width="674"><label for="subjects"></label>
                                        <div id="k">
                                            <select name="subjects" id="subjects"><option value="">Select Subject</option></select>
                                        </div>          </td>
                                </tr>
                                <tr>
                                    <td><h4>File Name</h4></td>
                                    <td><input type="text" name="name" id="name" /></td>
                                </tr>
                                <tr>
                                    <td><h4>Upload Pic</h4></td>
                                    <td><label for="f1"></label>
                                        <input type="file" name="f1" id="f1" /></td>
                                </tr>
                                <tr>

                                    <td><input type="submit" name="save" id="save" value="Submit" /></td>
                                </tr>
                            </table>
                        </form>
                    </td>
                </tr>
            </table>
        </div>

    </body>
</html>

2 个答案:

答案 0 :(得分:0)

上传图片或任何文件'enctype'应该被分配

 <form method="post" action="filupload.php" enctype="multipart/form-data">

答案 1 :(得分:0)

在表单标记中使用 enctype =&#34; multipart / form-data&#34; ,如:

 <form action="filupload.php" method="post" enctype="multipart/form-data">