User Tools

Site Tools


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

$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="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Upload Your File</title>
    <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" />

Run the server using php-cli package (php$version-cli)

# install the package (on a Debian based Linux) if needed
apt-get install php7.3-cli --no-install-recommends
# run the server on the same path as the upload.php script
php -S

Now you can access your uploader simple server on

And woola!!

docu/snipper/program/php_upload_file.txt · Last modified: 2020/08/20 21:18 by admin