<?php
$file = 'test.txt';
if(!file_exists($file)){
fopen($file,"w");
}
$getFile = file_get_contents($file);
if(isset($_POST['submit'])) {
$filetmp = $_FILES["image"]["tmp_name"];
$filename = $_FILES["image"]["name"];
$checker = getimagesize($filetmp);
if($checker !== false) {
$output = "success";
move_uploaded_file($filetmp, $filename);
file_put_contents($file, $filename);
}else{
$output = "error";
}
}
?>
<html>
<body>
<?php if(!empty($getFile)){ ?>
<img src="<?php echo file_get_contents($file); ?>"><br>
<p><?php echo 'https://'.$_SERVER['SERVER_NAME'].'/'.file_get_contents($file); ?></p>
<?php } ?>
<?php if(isset($output)){ ?>
<script>
alert('<?php echo $output; ?>');
window.location.reload();
</script>
<?php } ?>
<form action="#" method="POST" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" name="submit">
</form>
</body>
</html>