0byt3m1n1
Path:
/
var
/
www
/
listcrawler.app
/
public_html
/
admin
/
[
Home
]
File: add_sponsor.php
<?php session_start(); require_once 'config/config.php'; require_once BASE_PATH.'/includes/auth_validate.php'; // Serve POST method, After successful insert, redirect to lists.php page. if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Mass Insert Data. Keep "name" attribute in html form same as column name in mysql table. $data_to_db = array_filter($_POST); $db = getDbInstance(); $last_id = $db->insert('sponsors', $data_to_db); if ($last_id) { // Add pic 1 if(isset($_FILES['pic1']['name']) && $_FILES['pic1']['name']!='') { $pic=$_FILES['pic1']['name']; $path = pathinfo($pic); $filename = $path['filename']; $ext = $path['extension']; $final_pic = rand(10,100) . "" .time() . "." . $ext; $path = "../sponsor_pics/" . $final_pic; $thumb = "../sponsor_pics/" . $final_pic; move_uploaded_file($_FILES['pic1']['tmp_name'],$path); resizeImage($path, $thumb, 500, 650); $pic1_data = array( 'sponsor_id' => $last_id, 'photo_name' => $final_pic ); $db->insert('sponsor_photos', $pic1_data); } // Add pic 2 if(isset($_FILES['pic2']['name']) && $_FILES['pic2']['name']!='') { $pic=$_FILES['pic2']['name']; $path = pathinfo($pic); $filename = $path['filename']; $ext = $path['extension']; $final_pic = rand(10,100) . "" .time() . "." . $ext; $path = "../sponsor_pics/" . $final_pic; $thumb = "../sponsor_pics/" . $final_pic; move_uploaded_file($_FILES['pic2']['tmp_name'],$path); resizeImage($path, $thumb, 500, 650); $pic2_data = array( 'sponsor_id' => $last_id, 'photo_name' => $final_pic ); $db->insert('sponsor_photos', $pic2_data); } // Add pic 3 if(isset($_FILES['pic3']['name']) && $_FILES['pic3']['name']!='') { $pic=$_FILES['pic3']['name']; $path = pathinfo($pic); $filename = $path['filename']; $ext = $path['extension']; $final_pic = rand(10,100) . "" .time() . "." . $ext; $path = "../sponsor_pics/" . $final_pic; $thumb = "../sponsor_pics/" . $final_pic; move_uploaded_file($_FILES['pic3']['tmp_name'],$path); resizeImage($path, $thumb, 500, 650); $pic3_data = array( 'sponsor_id' => $last_id, 'photo_name' => $final_pic ); $db->insert('sponsor_photos', $pic3_data); } $_SESSION['success'] = 'Ad added successfully!'; // Redirect to the edit page header('Location: edit_sponsor.php?sponsor_id=' . $last_id . '&operation=edit'); // Important! Don't execute the rest put the exit/die. exit(); } else { echo 'Insert failed: ' . $db->getLastError(); exit(); } } // We are using same form for adding and editing. This is a create form so declare $edit = false. $edit = false; ?> <?php include BASE_PATH.'/includes/header.php'; ?> <div id="page-wrapper"> <div class="row"> <div class="col-lg-6"> <h2 class="page-header">Add Sponsored Ad</h2> </div> <div class="col-lg-6"> <div class="page-action-links text-right"> <a href="sponsors.php" class="btn btn-success"><i class="glyphicon glyphicon-chevron-left"></i> Sponsored Ad Listing</a> </div> </div> </div> <!-- Flash messages --> <?php include BASE_PATH.'/includes/flash_messages.php'; ?> <form class="form" action="" method="post" id="sponsor_form" enctype="multipart/form-data"> <?php include BASE_PATH.'/forms/sponsor_form.php'; ?> </form> </div> <script type="text/javascript"> $(document).ready(function(){ $('#sponsor_form').validate({ rules: { ad_title: { required: true, minlength: 6 }, ad_url: { required: true, minlength: 6 } } }); }); </script> <?php include BASE_PATH.'/includes/footer.php'; ?>