Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[php/mysql] Upload multi files

good afternon hackforums family ,
i got a problem when i want to upload multi files into mysql server i dont know where is my problem here i display many message to verify where is my problem and i didn't find any clue
my idea is to make a directory and put into many files (php/sql/html ...)
i need help guys please
php code to upload files
PHP Code

<?php 
//database configuration file 
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "github";
$description = $_POST["description"];
$dateTime=date('Y-m-d H:i:s');
$dirc = $_POST["directoryName"];
$user = $_SESSION["username"]; 
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die(
"Connection failed: " . $conn->connect_error);
}
echo 
"hello1";

if(isset(
$_POST['submit'])){ 
    
// File upload configuration 
    
$targetDir = "project1/"; 
    
$allowTypes = array('php','html','css','gif'); 
     
    
$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = ''; 
    
$fileNames = array_filter($_FILES['files']['name']); 
    echo 
"hello2";
    if(!empty(
$fileNames)){ 
      echo 
"hello3";
        foreach(
$_FILES['files']['name'] as $key=>$val){ 
            
// File upload path 
            
$fileName = basename($_FILES['files']['name'][$key]); 
            
$targetFilePath = $targetDir . $fileName; 
             echo 
"hello4";
            
// Check whether file type is valid 
            
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); 
            if(
in_array($fileType, $allowTypes)){ 
                
// Upload file to server 
                
echo "hello5";
                if(
move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){ 
                    
// Image db insert sql 
                    
echo "hello7";
                    
$insertValuesSQL .= ",('".'1'."','".$fileName."','".'2'."','".'3'."','".'4'."','".'5'."','".'6'."','".'7'."')"; 
                      echo 
"<br>".$insertValuesSQL."<br>";
                  }else{ 
                    
$errorUpload .= $_FILES['files']['name'][$key].' | '; 
                    
                  } 
            }else{ 
                
$errorUploadType .= $_FILES['files']['name'][$key].' | '; 
            } 
        } 
         
        
// Error message 
        
$errorUpload = !empty($errorUpload)?'Upload Error: '.trim($errorUpload, ' | '):''; 
        
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.trim($errorUploadType, ' | '):''; 
        
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType; 
         
        if(!empty(
$insertValuesSQL)){ 
            
$insertValuesSQL = trim($insertValuesSQL, ','); 
            echo 
"<br>".$insertValuesSQL;
            
// Insert image file name into database 
            
echo "hello6";
            
$insert = $db->query("INSERT INTO project VALUES $insertValuesSQL");
            echo 
"hello10";
            if(
$insert){ 
                
$statusMsg = "Files are uploaded successfully.".$errorMsg; 
            }else{ 
                
$statusMsg = "Sorry, there was an error uploading your file."; 
            } 
        }else{ 
            
$statusMsg = "Upload failed! ".$errorMsg; 
        } 
    }else{ 
        
$statusMsg = 'Please select a file to upload.'; 
    } 
} 
//header("Location: ../");
 
?>

html upload input



PHP Code

<?php 
<form method="POST" action="php/upload.php" enctype="multipart/form-data">
    <
div class="control-panel">
        <
label>Project folder name</label>
      <
input type="text" name="directoryName"><br>
      <
label>Project name</label>
      <
input type="text" name="projectName"><br>
      <
label>Project description</label>
      <
textarea name="description"></textarea><br>

      <
span>PUSH PROJECT</span>
      <
input type="file" name="files[]" multiple >
    </
div>
    <
input type="submit" name="submit" value="UPLOAD">
    [
b]<!--[/b]<input type="submit" class="uploadBtn button5" name="uploadBtn" value="Push" />-->
  </
form> 
Writeln('Give me a Target >');
[Image: giphy.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
by blackcoder00Apr 1, 2022 09:14 AM 6 163 Apr 1, 2022 09:14 AM
Last Post: Disease
by d0nj@nApr 29, 2014 08:02 PM 0 45 Apr 29, 2014 08:02 PM
Last Post: d0nj@n
by ʇsıʎqqoɥDec 27, 2008 08:26 AM 2 175 Dec 27, 2008 08:26 AM
Last Post: ʇsıʎqqoɥ