Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="stylesheet.css">
- <title>Image Upload</title>
- </head>
- <body>
- <div>
- <form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" enctype="multipart/form-data">
- <input type="hidden" name="size" value="1000000">
- <div>
- <input type="file" name="image">
- </div>
- <div>
- <textarea
- id="text"
- cols="40"
- rows="4"
- name="image_text"
- placeholder="Say something about this photo"></textarea>
- </div>
- <div>
- <button type="submit" name="upload">POST</button>
- </div>
- </form>
- <?php
- // Create database connection
- include("config.php");
- include("session.php");
- // Initialize message variable
- $msg = "";
- $image_text="";
- $user = $_SESSION['user'];
- // If upload button is clicked ...
- if (isset($_POST['upload'])) {
- // Get image name
- $image = $_FILES['image']['name'];
- // Get text
- $image_text = mysqli_real_escape_string($conn, $_POST['image_text']);
- // image file directory
- $target = "images/".basename($image);
- // Check if image file is a actual image or fake image
- $check = getimagesize($_FILES["image"]["tmp_name"]);
- if ($check){
- $stmt = $conn->prepare("INSERT INTO images (id, image, image_text ,user) VALUES (null, ?, ?, ?)");
- $stmt->bind_param("sss", $image, $image_text, $user);
- // execute query
- $result = $stmt->execute();
- if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
- $msg = "Image uploaded successfully";
- header ('Location: uploadPhoto.php');
- }else{
- $msg = "Failed to upload image";
- }
- }
- else{
- $msg = "Only images are allowed";
- }
- }
- echo $msg;
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement