0

I'm sorry to ask question that has been seen a lot of time, but it seems to not work for me, so I have to ask you guys ... Thanks in advance !

here is my html form :

<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>

and here is 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 !!';
    }
}

Hope you guys help me, thanks !!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

3 Answers3

3

If $_FILES["file"] gives undefined index file then there were no uploaded files.

You're missing enctype="multipart/form-data" in the form.

Halcyon
  • 57,230
  • 10
  • 89
  • 128
0

when your form includes any <input type="file"> elements use multipart/form-data:

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

Read more about multipart/form-data What does enctype='multipart/form-data' mean?

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33
-3

Try to change your form code as below:

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

I hope, it helps.

vural
  • 381
  • 2
  • 11