owo-tower-panel/u.php

49 lines
1.5 KiB
PHP

<?php
$target_dir = "o/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
$target_file = $target_dir . substr(md5_file($_FILES['file']['tmp_name']), 1, 6) . "." . $imageFileType;
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["file"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
echo "File appears to be missing";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Whoops! someone already uploaded that, " . $target_file;
$uploadOk = 0;
}
// Check file size
if ($_FILES["file"]["size"] > 6000000) {
echo "Sorry, your file is too large. (maximum size allowed 6mb)";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif"
&& $imageFileType != "ico"
&& $imageFileType != "tif"
&& $imageFileType != "tiff" ) {
echo "Sorry, only image 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 for an unknown reason.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "http://" . $_SERVER['HTTP_HOST'] . "/" . $target_file;
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>