未定义的索引文件(从这个论坛尝试了很多解决方案但没有工作......)

undefined index file (Tried a lot of solutions from this forum but not working ...)

很抱歉问了很多次的问题,但它似乎对我不起作用,所以我不得不问你们...... 提前致谢!

这是我的 html 表格:

<form action="action/actionindex.php" method="post">
<label style="text-align:center;"><b>Changer d'image</b></label>
    <input type="file" name="file" id="indeximage" style="margin-left:500px;"/>
    <div class="bg" style="background-image:url('../image/papierpeint.jpg');width:95%;margin:0 auto;height:auto;">
        <div class="welcometxt">
            <ul>

                <label><b>Titre de l'article (Saut de ligne : <img src="../image/sautligne.png"/>| Gras : <img src="../image/gras.png"/>| Italique : <img src="../image/italique.png"/>| Souligné : <img src="../image/souligne.png"/>)</b></label>
                <textarea name="indexh2" rows="1" cols="80">
                    <?php getDesc(1) ?>
                </textarea></br>
    <label><b>Contenu l'article (Saut de ligne : <img src="../image/sautligne.png"/>| Gras : <img src="../image/gras.png"/>| Italique : <img src="../image/italique.png"/>| Souligné : <img src="../image/souligne.png"/>)</b></label>
            <textarea name="indexp" rows="15" cols="110">
                <?php getDesc(2)?>
            </textarea>
            <input type="submit" name="submit" value="Modifier"></br>

这里是 actionindex.php :

if(isset($_POST['submit'])){
    $name = $_FILES['file']['name'];  
    echo 'nom : '.$name;
    $temp_name  = $_FILES['file']['tmp_name'];  
    echo 'dossier temp : '.$temp_name;
    if(isset($name)){
        if(!empty($name)){      
            $location = '../../image/';      
            if(move_uploaded_file($temp_name, $location)){
                echo 'File uploaded successfully';
            }
        }       
    }  else {
        echo 'You should select a file to upload !!';
    }
}

希望大家帮帮我,谢谢!!

尝试如下更改表单代码:

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

希望对你有帮助。

如果$_FILES["file"]给出undefined index file则没有上传文件。

您缺少 enctype="multipart/form-data" 表格。

当您的表单包含任何 <input type="file"> 元素时,请使用 multipart/form-data:

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

阅读更多关于 multipart/form-data What does enctype='multipart/form-data' mean?