Viewing file: add_course_action.php (2.3 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require("../connection.php");
session_start();
$title= $_POST["title"];
$hour= $_POST["hour"];
$placement= $_POST["placement"];
$cost= $_POST["cost"];
$description= $_POST["description"];
$targetDir = "/home4/srishtis/public_html/srishticampus/campus2020/packageImages/";
$fileName = basename($_FILES["image"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
$image = $fileName;
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false){
// $errors[]="extension not allowed, please choose a JPEG or PNG file.";
echo '<script>alert("extension not allowed, please choose a JPEG or PNG file.")</script>';
}
if($file_size > 2097152){
//$errors[]='File size must be excately 2 MB';
echo '<script>alert("File size must be excately 2 MB")</script>';
}
if(empty($errors)==true){
if(move_uploaded_file($_FILES["image"]["tmp_name"], $targetFilePath)){
$query="insert into course_details(`name`,`hour`,`placement`,`image`,`cost`,`status`,`description`)values('$title','$hour','$placement','$image','$cost',0','$description')";
$result=$con->query($query);
$count=$con->affected_rows;
if($count>0)
{
$msg = "successfully inserted";
header("location:course_add.php");
}
else
{
$msg = "Something went wrong";
header("location:course_add.php");
}
} else {
echo '<script>alert("File Upload not successfull")</script>';
}
}
else {
echo '<script>alert("Something went wrong!")</script>';
}
?>
|