Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('db.php');
- session_start();
- $session_id='1';
- $path = "uploads/";
- $imgtitle = $_POST['imgtitle'];
- $imgdesc = $_POST['imgdesc'];
- function getExtension($str)
- {
- $i = strrpos($str,".");
- if (!$i) { return ""; }
- $l = strlen($str) - $i;
- $ext = substr($str,$i+1,$l);
- return $ext;
- }
- $valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
- if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
- {
- $name = $_FILES['photoimg']['name'];
- $size = $_FILES['photoimg']['size'];
- if(strlen($name))
- {
- $ext = getExtension($name);
- if(in_array($ext,$valid_formats))
- {
- if($size<(5012*5012))
- {
- $actual_image_name = time().substr(str_replace(" ", "_", $ext), 5).".".$ext;
- $tmp = $_FILES['photoimg']['tmp_name'];
- if(move_uploaded_file($tmp, $path.$actual_image_name))
- {
- mysqli_query($db,"INSERT INTO `media` (title, description, image) VALUES ('$imgtitle', '$imgdesc', '$actual_image_name')");
- header('Location: media.php');
- }
- else
- echo "Fail upload folder with read access.";
- }
- else
- echo "Image file size max 1 MB";
- }
- else
- echo "Invalid file format..";
- }
- else
- echo "Please select image..!";
- exit;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement