PHP multiple upload files, tmp_name and others has no value, form post only name of picture

247 views Asked by At

How can I get the parameters from that POST form? When I tried

$_FILES['support_images']['tmp_name']

it's always empty so I can't store the path to database or fill the values.

Source code

if(isset($_POST['submit']))           
{
    extract($_POST);

    //sys_get_temp_dir();
    //echo "<pre>"; 
    //echo "POST:"; 
    //print_r($_POST); 
    //echo "FILES:"; 
    //print_r($_FILES); 
    //echo "</pre>";//vypis
    //phpinfo();

    if(isset($_FILES['support_images']['name']))
    {
        $file_name_all="";
        for($i=0; $i<count($_FILES['support_images']['name']); $i++) 
        {
            $tmpFilePath = $_FILES['support_images']['tmp_name'][$i];    
            if ($tmpFilePath != "")
            {    
                $path = "fotky/"; // create folder 
                $name = $_FILES['support_images']['name'][$i];
                $size = $_FILES['support_images']['size'][$i];

                list($txt, $ext) = explode(".", $name);
                $file= time().substr(str_replace(" ", "_", $txt), 0);
                $info = pathinfo($file);    //cesta
                $filename = $file.".".$ext;//meno
                if(move_uploaded_file($_FILES['support_images']['tmp_name'][$i], $path.$filename)) 
                { 
                    $file_name_all.=$filename."*";
                }

                $filepath = rtrim($file_name_all, '*').$path;    
                $query=mysqli_query($con,"INSERT into galeria_fotky (`img_path`,`img_name`,`img_galeria`) 
                    VALUES('".$path.$filename."','".$name."','".$_SESSION["galeria"]."'); ");
            } 
            else 
                echo "<br>Obrazok sa nepodarilo ulozit :(";     
        }
    }
    else
    {
        $filepath="";
    }
}

//////////////////////////KONIEC PRIDAVANIA/////////////////////////////////////////////////
?>
</div><br><br><br>
<h1>Upravuješ galériu: <?php echo ($_SESSION["galeria"]); ?></h1>


<form action="update_galeria.php?galeria=<?php echo ($_SESSION["galeria"]); ?>" method="POST" enctype="multipart/form-data">
    <div class="form-group">
        <label class="col-md-3 control-label"><h4>Pridať obrázky do galérie:</h4></label>
        <br>
            <div >
                <input type="file" id="file"  name="support_images[]" multiple accept="image/*" required/>
            </div>
    </div>

    <div class="form-group">
        <label class="col-md-3 control-label"></label>
            <div class="submit">
                <button class="registracia" value="submit " type="submit" name="submit">Pridať</button>
            </div>  
    </div>
</form>


<button class="registracia"  type="submit"  
onclick="window.location.href='update_galeria.php?galeria=<?php echo ($_SESSION["galeria"]); ?>'">Načítať galériu</button>


</body>
</html>
0

There are 0 answers