title: Resize uploaded image - PHP
body: <p>I am using the basic upload code from the w3schools website but I would like to add the ability to resize the image on upload to 200px wide. Is this something that can be simply added to this code or do I need a different approach to achieve this?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>    &lt;?php
  if ((($_FILES["file"]["type"] == "image/gif")
  || ($_FILES["file"]["type"] == "image/jpeg")
  || ($_FILES["file"]["type"] == "image/pjpeg"))
  &amp;&amp; ($_FILES["file"]["size"] &lt; 200000))
    {
    if ($_FILES["file"]["error"] &gt; 0)
      {
      echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
      }
    else
      {
      echo "Big Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
      echo "&lt;img src='upload/" . $_FILES["file"]["name"] . "' /&gt;&lt;br /&gt;";
      echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
      echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
      echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br /&gt;";
  
      if (file_exists("upload/" . $_FILES["file"]["name"]))
        {
        echo $_FILES["file"]["name"] . " already exists. ";
        }
      else
        {
        move_uploaded_file($_FILES["file"]["tmp_name"],
        "upload/" . $_FILES["file"]["name"]);
        echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        }
      }
    }
  else
    {
    echo "Invalid file";
    }
  ?&gt;
  </code></pre>