index.php

1 lines ASCII Unix (LF)
1
<?php
// Just to create the proper link to source.php
$self = $_SERVER['PHP_SELF']; $selfurl = 'http://dbwebb.se'.$self; $dirs=explode( '/', trim(__DIR__, '/')); $src_dir=end($dirs);

?><!doctype html>
<html lang='en'>
<head>
<meta charset=utf-8>
<title>Upload a file</title>
<style>
body{width:700px;}
</style>
</head>
<body>
<h1>Upload a file</h1>
<p>Sample script to upload file. The uploaded files are not stored on the server, just ignored.</p>

<form enctype="multipart/form-data" method="post">
<fieldset>
<legend>File upload</legend>
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
  <p>
    <label for='file'>File to upload:</label>
    <input name='file' type='file'>
  </p>
  <p>
    <input type='submit' name='doFileupload' value='Upload' />
  </p>
</fieldset>
</form>

<?php if(isset($_POST['doFileupload'])): ?>

<p><b>Form was submitted.</b></p>

<p><code>$_FILES</code>:</p>
<pre><?=print_r($_FILES, true)?></pre>

<p><code>$_POST</code>:</p>
<pre><?=print_r($_POST, true)?></pre>

<p>Verifying file upload:</p>

<?php
if(is_file($_FILES['file']['tmp_name'])) {
  echo "<p><b>SUCCESS: The uploaded file seems to exists at the server.</b></p>";
} else {
  echo "<p><b>FAILURE: The uploaded file DOES NOT seem to exists at the server.</b></p>";
}

$dir = __DIR__ . "/tmp/";
if(is_dir($dir) && is_writable($dir)) {  
  $filename = $dir . basename($_FILES['file']['name']);
  if(move_uploaded_file($_FILES['file']['tmp_name'], $filename)) {
    echo "<p><b>SUCCESS: The uploaded file was moved in place (and then deleted).</b></p>";
    @unlink($filename);
  } else {
    echo "<p><b>FAILURE: Could not move the uploaded file in place.</b></p>";
  }
} else {
  echo "<p><b>INFO: File upload is disabled and the file is not moved in place.</b></p>";
}

?>


<?php else: ?>

<p><b>Form was NOT submitted.</b></p>

<?php endif; ?>


<p>
  <a href="http://validator.w3.org/check/referer">HTML5</a>  
  <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>
  <a href="http://jigsaw.w3.org/css-validator/check/referer?profile=css3">CSS3</a>
  <a href="http://validator.w3.org/unicorn/check?ucn_uri=referer&amp;ucn_task=conformance">Unicorn</a>
  <a href="http://validator.w3.org/i18n-checker?docAddr=<?=$selfurl?>">i18n</a>
  <a href="../source.php?dir=<?=$src_dir?>&amp;file=<?=basename($self)?>#file">Sourcecode</a>
</p>
</body>
</html>