started working on adding temp file upload feature

This commit is contained in:
Luke Ogburn
2019-09-26 00:18:24 -04:00
parent 12ab5aa220
commit fcf999e427
2 changed files with 55 additions and 1 deletions

View File

@@ -32,7 +32,15 @@
}
?>
</div>
<div class=fileUpload>
<form action="" method=POST>
<input type=file name=fileUpload[] multiple>
<button type=submit>
</form>
</div>
<input type=checkbox id=boo>
<div id=cookie><p><label for=boo>This site does <b>not</b> use cookies. You're welcome.</label></p></div>
</body>
</html>
</html>

46
upload/submit.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
function randID($length = 4) {
//Note that $length must be even, or it will round down
do{
if(function_exists("random_bytes")){
$bytes = random_bytes(ceil($length/2));
}elseif(function_exists("openssl_random_pseudo_bytes")){
$bytes = openssl_random_pseudo_bytes(ceil($length/2));
}else{
throw new Exception("No cryptographically secure random function available.");
}
$x = substr(bin2hex($bytes), 0, $length);
$id = strtolower(gmp_strval(gmp_init($x, 36), 62));
} while(!verifyID($id));
return $id;
}
$pid = randID();
$file = $_FILES["images"];
if($file["name"][0]!=NULL){
for($i=0; $i<sizeof($file["name"]); $i++){
$ext = explode('.', $file["name"][$i]);
$ext = strtolower($ext[sizeof($ext)-1]);
$allowedExt = array('jpg', 'jpeg', 'png', 'doc', 'docx', 'pdf');
if(in_array($ext, $allowedExt)){
if(!$file["error"][$i]){
$imgDest = randID().".".$ext;
$img .= $imgDest.",";
$dest = $_SERVER['DOCUMENT_ROOT']."/forum/images/".$imgDest;
move_uploaded_file($file["tmp_name"][$i], $dest);
}else{
echo "Error uploading file";
exit();
}
}else{
msg("Bad file type.");
header("Location: /post");
exit(); //this is needed for some reason
}
}
}else{
$img = NULL;
}
?>