title: OOP upload images in the folder
body: <p>I'm working uploading picture into the folder, applications work, but first time when I open the page to upload a image I have few error message, when I upload picture then there no error message  end I can uploading as many I want without error. When I again click or reload page first time a have error and after first uploading errors gone. </p>
  
  <p>I have folder images</p>
  
  <pre><code>File: pictureupload.php
  File: classimage.php
  </code></pre>
  
  <p>Code for pictureupload.php is</p>
  
  <pre><code>&lt;?php
  include_once 'classimage.php';
  $img= new images();
  
  $img-&gt;uploadImages();
  
  ?&gt;
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form action="index.php" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="file" name="picture" &gt;
  &lt;br&gt;&lt;br&gt;
  
  &lt;input type="submit" name="upload" value="Upload Picture"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Code for  classimage.php is</p>
  
  <pre><code>&lt;?php
  class images
  {
  protected $fileName;
  protected $fileTmp;
  protected $fileType;
  protected $fileSize;
  protected $fileError;
  
  public function __construct()
  {
  $this-&gt;fileName = $_FILES['picture']['name'];
  $this-&gt;fileTmp = $_FILES['picture']['tmp_name'];
  $this-&gt;fileSize = $_FILES['picture']['size'];
  $this-&gt;fileError = $_FILES['picture']['error'];
  $this-&gt;fileType =$_FILES['picture']['type'];
  }
  
  public function uploadImages()
  {
  //if Button push
  if(isset($_POST['upload']) &amp;&amp; $_POST['upload']=='Upload Picture')
  {
  //get type after .
  $kabom = explode(".", $this-&gt;fileName);
  //get image type
  $fileExtnsion = end($kabom);
  $fileName = time().rand().".".$fileExtnsion;
  
  if(!$this-&gt;fileTmp)
  {
  echo "Error: Please browse for a file before clicking the upload button";
  exit();
  }
  elseif ($this-&gt;fileSize &gt; 5242880)
  {
  echo "Error: Your file was large than 5MB";
  unlink($this-&gt;fileTmp);
  exit();
  }
  elseif (!preg_match("/.(gif|jpg|png)$/i", $this-&gt;fileName))
  {
  echo "ERROR: Your image was not .gif, .jpg, or .png.";
  unlink($this-&gt;fileTmp);
  exit();
  }
  
  
  elseif ($this-&gt;fileError==1)
  {
  echo "Error.Please try again";
  exit();
  }
  $movePicture = move_uploaded_file($this-&gt;fileTmp, "images/$fileName");
  if($movePicture == false)
  {
  echo "Error File not uploaded.";
  exit();
  }
  }
  }
  }
  ?&gt;
  </code></pre>
  
  <p>FIrst time when I upload picture I have this error</p>
  
  <pre><code>Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 12
  
  Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 13
  
  Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 14
  
  Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 15
  
  Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 16
  </code></pre>
  
  <p>This error is from file classimage.php</p>
  
  <pre><code>$this-&gt;fileName = $_FILES['picture']['name']; - line12
  $this-&gt;fileTmp = $_FILES['picture']['tmp_name']; - line 13
  $this-&gt;fileSize = $_FILES['picture']['size']; - line 14
  $this-&gt;fileError = $_FILES['picture']['error']; - line 15
  $this-&gt;fileType =$_FILES['picture']['type']; - line 16
  </code></pre>