Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (!isset($_SESSION['username'])) {
- $_SESSION['msg'] = "You must log in first";
- header('location: login.php');
- }
- if (isset($_GET['logout'])) {
- session_destroy();
- unset($_SESSION['username']);
- header("location: login.php");
- }
- $host = '127.0.0.1';
- $db = 'my_testme';
- $user = 'testme';
- $pass = '';
- $charset = 'utf8mb4';
- $options = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $pdo = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass, $options);
- $stmt = $pdo->prepare("SELECT * FROM users WHERE username=?");
- $stmt->execute(array($_SESSION["username"]));
- // using while
- while($row = $stmt->fetch()) {
- $id = $row["id"];
- }
- $title = $_POST["title"];
- $apps = $_POST["napps"];
- $des = $_POST["description"];
- $earn = 0;
- $image = rand(5,99999999);
- $sql = "INSERT INTO image (userid, title, napps, des, earnings, image) VALUES (?, ?, ?, ?, ?, ?)";
- $pdo->prepare($sql)->execute([$id, $title, $apps, $des, $earn, $image]);
- $stmt = $pdo->prepare("SELECT * FROM image WHERE image=?");
- $stmt->execute(array($image));
- // using while
- while($row = $stmt->fetch()) {
- $idimage = $row["id"];
- }
- // Upload and Rename File
- if (isset($_POST['file']))
- {
- $filename = $_FILES["file"]["name"];
- $file_basename = substr($filename, 0, strripos($filename, '.')); // get file extention
- $file_ext = substr($filename, strripos($filename, '.')); // get file name
- $filesize = $_FILES["file"]["size"];
- $allowed_file_types = array('.jpg','.png','.jpeg','.gif');
- if (in_array($file_ext,$allowed_file_types)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement