0

{ currently, all the samples I have seen so far are mainly for a single file upload. thank you in advance. i'm a student and this is my first task. I would equally love to download or save the files from data base back to my computer. I wrote the code in php and sql, my problem is that each time i try uploading the files to xampp free database,I keep on receiving one file instead of two files in my folder I really need a professional way to do it and avoid users from submitting the same file twice. Thanks.

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="post.php" method="POST" enctype="multipart/form-data">
    <input type="file" class="videofile" name="videofile">
    <input type="file" class="picturefile" name="picturefile">
    <input type="submit" class="submit" name="submit">
    </form>
</body>
</html>


    MYSQL
    
    CREATE TABLE userstable(id int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
     VARCHAR (200) NOT NULL,
    videofile VARCHAR (200) NOT NULL,
    picturefile VARCHAR (200) NOT NULL,
    
    <?php
    
    include "connect.php";
    
    if(isset($_POST['submit'])){
    $videofile = $_FILES['vfile']['name'];
    $picturefile = $_FILES['pfile']['name'];
    
    $folder = "uploads/";
    
    
    if ($videofile == "" || $picturefile == ""){
        echo "Sorry, your file was not uploaded, ensure all filed are filed.";
    }
    
    else{
        move_uploaded_file($folder.$videofile, folder.$picturefile);
    
     
    
    
    mysqli_query ($user, "INSERT INTO usertable(videofile, picturefile) VALUES('$videofile', '$picturefile')");
    
        echo "Registration successful!";
    }
    }
    ?> }
Jeff
  • 3
  • 3
  • 1
    We’ll need to see part of your HTML, but [this](https://stackoverflow.com/a/12006515/231316) outlines the basics. Server-side, I’m not seeing anything that’s looking for multiple files, which is usually a loop – Chris Haas Jun 11 '22 at 23:56
  • Document – Jeff Jun 12 '22 at 01:10
  • That's the html file. First input is for a video file while the second input is for a picture file – Jeff Jun 12 '22 at 01:11
  • Please edit your question with the relevant HTML – Chris Haas Jun 12 '22 at 04:11
  • The function `move_uploaded_file` is source/destination. That function needs to be called with each uploaded file – Chris Haas Jun 12 '22 at 04:14
  • I've edited the question and the html code is now included in it. Please can I see a sample code on how to do that. Thanks. – Jeff Jun 12 '22 at 10:16

1 Answers1

0

You need to call move_uploaded_file() twice: once for the video file and once for the picture file.

move_uploaded_file($_FILES['vfile']['tmp_name'], folder.$videofile);
move_uploaded_file($_FILES['pfile']['tmp_name'], folder.$picturefile);

The first argument is the name of the file on the server and the second argument is the name of the destination file.

You should also check the return value; see the move_uploaded_file() documentation.

kmoser
  • 8,780
  • 3
  • 24
  • 40