move_uploaded_file在PHP中不起作用

内克

我正在使用PHP做考试系统。我正在尝试向图像添加问题,并将图像移到指定的文件夹中以进行检索。我有以下代码:

$sql = 'SELECT q_category, q_image, q_question, q_correct, q_answer2,     q_answer3, q_answer4 FROM tblquestions WHERE q_question = "' . $question . '"';

$retval = mysql_query($sql,$conn);
if(!$retval)
{
    die('Could not get data: ' . mysql_error());
}

while($row1 = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    $cat = $row1['q_category'];
    $quest = $row1['q_question'];
    $image = $row1['q_image'];
    $correct = $row1['q_correct'];
    $ans2 = $row1['q_answer2'];
    $ans3 = $row1['q_answer3'];
    $ans4 = $row1['q_answer4'];

    echo '<tr>';
    echo '<td colspan="2"><div class="selectText" align="center">Edit     Questions</div></td></tr>';
    echo '<tr>';
    echo '<td>Category</td>';
    echo '<td><input type="text" name="txtCategory" value = "' . $cat . '"   size="38"></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td>Question</td>';
    echo '<td><textarea rows="4" cols="34" name="txtQuestion" id="txtQuestion"  class="addNew">' . $quest . '</textarea>';
    echo '</tr>';
    echo '<tr>';
    echo '<td>Image</td>';
    echo '<td><input type="file" rows="4" cols="28" name="txtImage"  id="txtImage" class="addNew"></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td>Correct Answer</td>';
    echo '<td><input type="text" name="txtCorrect" value = "' . $correct . '"  size="38"></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td>Answer 2</td>';
    echo '<td><input type="text" name="txtChoice2" value = "' . $ans2 . '"  size="38"></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td>Answer 3</td>';
    echo '<td><input type="text" name="txtChoice3" value = "' . $ans3 . '" size="38"></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td>Answer 4</td>';
    echo '<td><input type="text" name="txtChoice4" value = "' . $ans4 . '" size="38"></td>';
    echo '</tr>';
    echo '<input type="hidden" name="hiddenQuestion" value = "' . $question .  '">';
}

if(isset($_POST['submit1']))
{
    $hiddenQuestion = $_POST['hiddenQuestion'];
    $addCategory = $_POST['txtCategory'];
    $addQuestion = $_POST['txtQuestion'];
    $addCorrect = $_POST['txtCorrect'];
    $addChoice2 = $_POST['txtChoice2'];
    $addChoice3 = $_POST['txtChoice3'];
    $addChoice4 = $_POST['txtChoice4'];

    $filetmp = $_FILES['txtImage']['tmp_name'];
    $filename = $_FILES['txtImage']['name'];
    $filepath = "questionImages/".$filename;

    move_uploaded_file($filetmp,$filepath);

单击提交后,$ filename在数据库中为空,并且move_uploaded_file不起作用。如果我将$ filename = $ _FILES ['txtImage'] ['name']更改为$ filename = $ _POST ['txtImage'],它将名称添加到数据库中,但是move_uploaded文件仍然不起作用。

问题我在想我的$ filetmp和$ filename出了点问题。谁能指出我的代码出了什么问题?提前致谢 :)

莫德·莫赫德(Moid Mohd)

$filename$filetype似乎确定。

在您的上传表单中检查是否包含enctype="multipart/form-data"

在问题中还包括您的表单代码。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章