Initial commit
This commit is contained in:
84
public/index.php
Executable file
84
public/index.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
error_reporting(E_ERROR | E_PARSE);
|
||||
if(isset($_FILES['image'])){
|
||||
$errors= array();
|
||||
$file_name = $_FILES['image']['name'];
|
||||
$file_size =$_FILES['image']['size'];
|
||||
$file_tmp =$_FILES['image']['tmp_name'];
|
||||
$file_type=$_FILES['image']['type'];
|
||||
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
|
||||
|
||||
if(empty($file_name)){
|
||||
$errors[] = 'Vennligst velg en fil.';
|
||||
}
|
||||
|
||||
if(empty($file_tmp)){
|
||||
$errors[] = 'Feil med server oppsett. Kontakt en server administrator og prøv igjen senere.'; # Increase upload and post size in php.ini
|
||||
}
|
||||
|
||||
$extensions= array("jpeg","jpg","png", "gif");
|
||||
|
||||
if(in_array($file_ext,$extensions)=== false){
|
||||
$errors[] = "Filtypen er ikke tillatt. Velg en JPEG, PNG eller GIF-fil.";
|
||||
}
|
||||
|
||||
# Check if the image is valid and not some bogus (dont know if this works yet)
|
||||
if(!is_image($file_tmp)) {
|
||||
$errors[] = 'Filtypen er ikke tillatt. Velg en JPEG, PNG eller GIF-fil.';
|
||||
}
|
||||
|
||||
if($file_size > 8000000){
|
||||
$errors[] = 'Filstørrelsen må ikke være større enn 8 MB.';
|
||||
}
|
||||
|
||||
if(empty($errors)==true){
|
||||
if(anti_spam()) {
|
||||
$errors[] = 'AntiSpam: Vennligst vent og prøv igjen.';
|
||||
} else {
|
||||
move_uploaded_file($file_tmp,"./uploads/unaudited/".time().".".$file_ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function is_image($path)
|
||||
{
|
||||
$a = getimagesize($path);
|
||||
$image_type = $a[2];
|
||||
|
||||
if(in_array($image_type, array(IMAGETYPE_GIF , IMAGETYPE_JPEG ,IMAGETYPE_PNG)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function anti_spam() {
|
||||
$last_time = file_get_contents("../anti_spam/index.txt");
|
||||
$seconds = time() - $last_time;
|
||||
if($seconds < 10) {
|
||||
return true;
|
||||
} else {
|
||||
file_put_contents("../anti_spam/index.txt", time());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php include('../_header.php'); ?>
|
||||
|
||||
<h3>Send inn bilde som skal revideres</h3>
|
||||
|
||||
<form style="border: 1px solid #888; padding: 10px; border-radius: 2px;" action="" method="POST" enctype="multipart/form-data">
|
||||
<?php
|
||||
if(isset($errors)==true) {
|
||||
if(empty($errors)==true) {
|
||||
print("<small style='color: green;'>Supert! Filen din er lastet opp og vil bli vurdert snarest.</small><br><br>");
|
||||
} else {
|
||||
print("<small style='color: red;'>".$errors[0]."</small><br><br>");
|
||||
}
|
||||
}
|
||||
?>
|
||||
Ditt bilde: <input type="file" name="image" /> <br> <br>
|
||||
<input type="submit" value="Last opp"/>
|
||||
</form>
|
||||
|
||||
<?php include('../_footer.php'); ?>
|
||||
Reference in New Issue
Block a user