lundi 20 avril 2015

PHP Multiple file upload with multiple inputs

I'm new to PHP. Now i have a problem with files upload. All files are moved, but It didn't store file's name to database. and it didn't show error. I have no idea to fix this one. Please help me out.

        <form method="post" action="index.php?insert_ads" enctype="multipart/form-data">

        <input type="file" name="b1" id="b1"/>

                    <b>Link</b></br>

                    <input type="text" id="b1l" name="b1l" class="form-control"/></br>

        <b>Home Small</b> <b style="color: blue;">100 x 100 px</b></br>

        <input type="userfile" name="b2" id="b2"/><br>

                    <b>Link</b></br>

                    <input type="text" id="b2l" name="b2l" class="form-control"/></br>

        <input type="submit" name="submit" value="Publish"/>

</form></br>

<?php 

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

    $b1 = $_FILES['b1']['name'];

     $tmp1 = $_FILES['b1']['tmp_name'];

             $b1l = $_POST['b1l'];

     $b2 = $_FILES['b2']['name'];

     $tmp2 = $_FILES['b2']['tmp_name'];

             $b2l = $_POST['b2l'];

    move_uploaded_file($tmp1,"ads/$b1");
    move_uploaded_file($tmp2,"ads/$b2");

    $insert_posts = "insert into ads (b1,b2) value ('$b1','$b2')";

    $run_posts = mysql_query($insert_posts);

}

?>

Aucun commentaire:

Enregistrer un commentaire