0

I found the code below online to import multiple images in the database, however the following condition seems to always return false because the code inside is never executed: (move_uploaded_file($tmpFilePath, $filePath)). Is it because of the path? I didn't change anything and I assumed that uploaded is created automatically.

<?php include 'connection.php';?>
<?php
if(isset($_POST['search'])){
    if(count($_FILES['upload']['name']) > 0){
        echo "OhhYESHOOO";
        //Loop through each file
        for($i=0; $i<count($_FILES['upload']['name']); $i++) {
          //Get the temp file path
            $tmpFilePath = $_FILES['upload']['tmp_name'][$i];
            echo "HERE";

            //Make sure we have a filepath
            if($tmpFilePath != ""){
            echo "Entered";
                //save the filename
                $shortname = $_FILES['upload']['name'][$i];
                //echo "*$shortname";
                //save the url and the file
                $filePath = "uploaded/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];

                //Upload the file into the temp dir
                if(move_uploaded_file($tmpFilePath, $filePath)) {
                    echo "Entered Again";
                    $files[] = $shortname;
                    //insert into db 
                    //use $shortname for the filename
                    //use $filePath for the relative url to the file

                }
              }
        }
    }

    //show success message
    echo "<h1>Uploaded:</h1>";    
    if(is_array($files)){
        echo "<ul>";
        foreach($files as $file){
            echo "<li>$file</li>";
        }
        echo "</ul>";
    }
}
?>
Bobby
  • 496
  • 5
  • 18

0 Answers0