title: Uploading file with PHP and PowerShell
body: <p>I want to upload to my website via PowerShell.</p>
  <p>When I use a simple HTML file the uploaded file appears in the folder, but when I use PowerShell I get the error code 200 and the file is not uploaded.</p>
  <p>I am using this code (source: <a href="https://www.w3schools.com/php/php_file_upload.asp" rel="nofollow noreferrer">PHP File Upload</a>):</p>
  <p>PHP:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  $target_dir = &quot;uploads/&quot;;
  $target_file = $target_dir . basename($_FILES[&quot;fileToUpload&quot;][&quot;name&quot;]);
  $uploadOk = 1;
  $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  
  // Check if image file is a actual image or fake image
  if(isset($_POST[&quot;submit&quot;])) {
    $check = getimagesize($_FILES[&quot;fileToUpload&quot;][&quot;tmp_name&quot;]);
    if($check !== false) {
      echo &quot;File is an image - &quot; . $check[&quot;mime&quot;] . &quot;.&quot;;
      $uploadOk = 1;
    } else {
      echo &quot;File is not an image.&quot;;
      $uploadOk = 0;
    }
  }
  
  // Check if file already exists
  if (file_exists($target_file)) {
    echo &quot;Sorry, file already exists.&quot;;
    $uploadOk = 0;
  }
  
  // Check file size
  if ($_FILES[&quot;fileToUpload&quot;][&quot;size&quot;] &gt; 500000) {
    echo &quot;Sorry, your file is too large.&quot;;
    $uploadOk = 0;
  }
  
  // Allow certain file formats
  if($imageFileType != &quot;jpg&quot; &amp;&amp; $imageFileType != &quot;png&quot; &amp;&amp; $imageFileType != &quot;jpeg&quot;
  &amp;&amp; $imageFileType != &quot;gif&quot; ) {
    echo &quot;Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.&quot;;
    $uploadOk = 0;
  }
  
  // Check if $uploadOk is set to 0 by an error
  if ($uploadOk == 0) {
    echo &quot;Sorry, your file was not uploaded.&quot;;
  // if everything is ok, try to upload file
  } else {
    if (move_uploaded_file($_FILES[&quot;fileToUpload&quot;][&quot;tmp_name&quot;], $target_file)) {
      echo &quot;The file &quot;. htmlspecialchars( basename( $_FILES[&quot;fileToUpload&quot;][&quot;name&quot;])). &quot; has been uploaded.&quot;;
    } else {
      echo &quot;Sorry, there was an error uploading your file.&quot;;
    }
  }
  ?&gt;
  </code></pre>
  <p>HTML:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
    Select image to upload:
    &lt;input type="file" name="fileToUpload" id="fileToUpload"&gt;
    &lt;input type="submit" value="Upload Image" name="submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>and PowerShell:</p>
  <pre class="lang-powershell prettyprint-override"><code>Invoke-Webrequest -URI &quot;https://example.com/upload.php&quot; -Method POST -InFile &quot;C:\Users\markus\Desktop\abc.png&quot; -Debug
  </code></pre>
  <p>This is the error/debug message that I get:</p>
  <pre class="lang-powershell prettyprint-override"><code>DEBUG: POST with -1-byte payload
  DEBUG: received 114-byte response of content type text/html; charset=UTF-8
  
  
  StatusCode        : 200
  StatusDescription : OK
  Content           : 
                      Sorry, file already exists.Sorry, only JPG, JPEG, PNG &amp; GIF files are allowed.Sorry, your file was not uploaded.
  RawContent        : HTTP/1.1 200 OK
                      Vary: User-Agent
                      Content-Length: 114
                      Content-Type: text/html; charset=UTF-8
                      Date: Sun, 03 Apr 2022 17:29:37 GMT
                      Server: Apache/2.4.53 (Unix)
                      X-Powered-By: PHP/8.0.17
  </code></pre>
  <p>So, what I am doing false and how should I use the Invoke-WebRequest command correct to upload an image?</p>