php_file_upload_table

 <Form action="upload.php" method="post" enctype="multipart/form-data">


        <input type="file" name="F" id="">
  <button name="upload" value="upload">Upload</button>
    </Form>

making connection:---
<?php
$con = mysqli_connect("localhost""root""""employee") or die("not connect");
// if (isset($con)) {
//     echo "this is connected";
// }
crete upload_files folder also....
uploadpage:-
<?php
session_start();
include "sql_connect.php";
if(isset($_POST['upload'])){
    //echo "file is going to upload";
    if(isset($_FILES['F']))
    {
       // print_r($_FILES['F']);
       $file_name=$_FILES['F']['name'];
$file_type=$_FILES['F']['type'];
$file_size=$_FILES['F']['size'];
$file_tmpname=$_FILES['F']['tmp_name'];
//echo $file_tmpname;
$fileNameCmps = explode("."$file_name);//breaks a string into an array..

$fileExtension = strtolower(end($fileNameCmps));
    //$newFileName=$file_name.'.'.$fileExtension;
    $allowedfileExtensions = array('jpg''gif''png''zip''txt''xls''doc');
    if(in_array($fileExtension,$allowedfileExtensions)){
        $uploadFileDir = 'uploaded_files/';
      $dest_path = $uploadFileDir . $file_name;
     // echo $dest_path;
      if(move_uploaded_file($file_tmpname$dest_path)) 
      {
        $sql_query = "INSERT INTO image_upload (sno,image_path)
        VALUES ('','{$dest_path}')";
         $query = mysqli_query($con$sql_query) or die("not executing");
        $message ='File is successfully uploaded.';
      }
      else
      {
        $message = 'There was some error moving the file to upload directory. Please make sure the upload directory is writable by web server.';
      }
    }
    else
    {
      $message = 'Upload failed. Allowed file types: ' . implode(','$allowedfileExtensions);
    }
    }
}
$_SESSION['message'] = $message;
header("Location: A.php");
?>

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation