simple-upload-app/upload_base/upload.php
2020-11-19 00:41:44 +01:00

25 lines
676 B
PHP
Executable file

<?php
// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip','pdf');
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
$nname = md5($_FILES['upl']['name']);
$mag = end(array_values(explode(".",$_FILES['upl']['name'])));
//if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$nname.$_FILES['upl']['name'])){
if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$nname.'.'.$mag)){
echo '{"status":"success"}';
exit;
}
}
echo '{"status":"error"}';
exit;