title: PHP image upload
body: <p>I am trying to upload an image to server using PHP and save inside a dir, and then returning the image url.</p>
  
  <p>html code:</p>
  
  <pre><code> &lt;form method="post"&gt;
    &lt;fieldset&gt;
      &lt;div class="form-group col-md-6 col-lg-6 col-sm-12"&gt;
         &lt;input type="file" class="form-control" name="image" required="required"&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
         &lt;button type="submit" name="Save" class="btn btn-primary"&gt;Create&lt;/button&gt;
      &lt;/div&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p>PHP code for upload image:</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['Save']))
      {
       /*image */
       $traget_dir="image/";
       $traget_file=$traget_dir .basename($_FILES["image"]["name"]);
       $uploadOk=1;
       $imageFileType = pathinfo($traget_file,PATHINFO_EXTENSION);
       $check=getimagesize($_FILES["image"]["tmp_name"]);
       if($check !== false) {
          echo "File is an image - " . $check["mime"] . ".";
          $uploadOk = 1;
       } else{
          echo "File is not an image.";
         $uploadOk = 0;
       }
       /*end image upload*/
      }
      ?&gt;
  </code></pre>
  
  <p>error on upload time:</p>
  
  <blockquote>
    <p>Notice: Undefined index: image in</p>
  </blockquote>
  
  <p>second error-></p>
  
  <blockquote>
    <p>Warning: getimagesize() [function.getimagesize]: Filename cannot be
    empty in</p>
  </blockquote>
  
  <p>thank for help and view.</p>