User Tools

Site Tools


docu:snipper:program:php_upload_file

This is an old revision of the document!


Run a simple php server to upload files


Simply, put this code snippet in an upload.php file somewhere, and run a simple php server using the cli

upload.php
<?php
 
$target = 'uploads/';
@mkdir($target, 0755);
 
if (isset($_POST['submit'])) {
  $target = 'uploads/'; @mkdir($target, 0755);
  move_uploaded_file( $_FILES['file']['tmp_name'], \
    $target.$_FILES['file']['name'] );
  echo 'The file was uploaded successfully<br><br>';
}
 
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Upload Your File</title>
  </head>
  <body>
    <div id="container">
      <form enctype="multipart/form-data" action="" method="post">
        <label for="file">Choose a file to upload:</label>
        <input id="file" type="file" name="file" /><br/>
        <input type="submit" value="upload file" name="submit" />
      </form>
    </div>
  </body>
</html>
docu/snipper/program/php_upload_file.1597958072.txt.gz · Last modified: 2020/08/20 21:14 by admin