php code

sneha asked 2 years ago

sir if we click view button it should view all the uploaded files in that page
plz get me code
 
<form action=”include/uploadDocs1.php” method=”post” enctype=”multipart/form-data”>
          <label> Select File: <input type=”file” name=”files[]” multiple> </label>
         <input type=”submit”  value=”Upload” name=”submit” >
              <button type=”button” class=”btn btn-default”>view</button>
              </form>
 
    <?php
$con = mysqli_connect(“localhost”,”root”,””,”sample”);
if(!$con){
echo “Error connecting Database”.mysqli_error($conn);
}
$date = date(“Y/m/d”);
$file_Version = date(“Y_m_d_H_m_s”);
$title = “sample files”;
$user = “sneha@gmail.com”;
 
if(!empty($_FILES[‘files’][‘name’][0])){
$files = $_FILES[‘files’];
$uploaded = array();
$failed = array();
$allowed = array(‘txt’,’jpg’,’docx’,’pdf’);
foreach($files[‘name’] as $position=>$file_name){
$file_temp = $files[‘tmp_name’][$position];
 
$file_size = $files[‘size’][$position];
$file_error = $files[‘error’][$position];
$file_ext = explode(‘.’,$file_name);
$file_ext=strtolower(end($file_ext));
if(in_array($file_ext,$allowed)){
if($file_error ===0){
if($file_size <=2097152){
 
$file_destination=’uploadDocs/’.$file_name .$file_Version.’.’ .$file_ext;
if(move_uploaded_file($file_temp,$file_destination)){
$uploaded[$position]=$file_destination;
 
$query = “INSERT INTO files(user, uploadDate, Title, filepath) VALUES (‘”.$user.”‘,’”.$date.”‘,’”.$title.”‘,’”.$file_destination.”‘)”;
$res = mysqli_query($con, $query);
if($res){
//echo “Successs”;
}else{
echo “Failed to insert”;
}
}else{
$failed[$position]= “[{$file_name}] failed to upload.”;
}
}
else{
$failed[$position]= “[{$file_name}] is too large.”;
}
}
else{
$failed[$position]= “[{$file_name}] errored with code {$file_error}.”;
}
}
else{
$failed[$position]= “[{$file_name}] file extension ‘{$file_ext}’ is not allowed.”;
}
}
 
 
 
 
if(!empty($uploaded)){
$query = “select uploadDate , filepath from files where user=’”.$user.”‘”;
echo $query;
$res = mysqli_query($con,$query);
if($res){
while ($row=mysqli_fetch_row($res))
    {
    echo “<div>Date:”.$row[0].”<span style=’margin-left:30px;’>File path: “.$row[1]. “</span></div>”;;
    }
}else{
echo “Err”;
}
}

Positive SSL