<?php include('server.php') ?> <?php session_start(); if (!isset($_SESSION['username'])) { $_SESSION['msg'] = "You must log in first"; header('location: Login.php'); } $username = $_SESSION['username']; ?> <!DOCTYPE html> <html> <head> <title>Upload - wfsecs-kingdom</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="navbar"> <a class='btn' href="../main.php">Main</a> <a class='btn' href="../Credits/">Credits</a> <a class='btn' href="../Chat/">Chat</a> <a class='btn' href="index.php">Profile</a> </div> <div id="content"> <form action="upload.php" method="post" enctype="multipart/form-data"> <style type="text/css"> color:white ; </style> <label>Upload Image</label> <input type="file" name='myfile'> <br/> <input type="submit" value="upload" name="submit"> </form> </body> </html> <?php $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["myfile"]["tmp_name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["myfile"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; upload(); $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists. "; $uploadOk = 0; } // Check file size if ($_FILES["myfile"]["size"] > 1000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") { echo "Sorry, only JPG, JPEG, PNG files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { upload(); function upload() { if (move_uploaded_file($_FILES["myfile"]["tmp_name"], $target_file)) { echo "The file ". htmlspecialchars( basename( $_FILES["myfile"]["tmp_name"])). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } } ?>
$target_file
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)