<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
    $error = "Error";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 2024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?> 
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$new =  "upload/" . $_FILES["file"]["name"];
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 1024)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        $error = "File Error";
    }
  else
    {
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
            $error = "File already exists";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        $error = "Uploaded";          
      }
    }
  }
else
  {
  echo "Invalid file";
?> 
<?php
$cid = htmlentities($_GET['id']);
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = "INSERT INTO photo (cid, path) VALUES ('$cid', '$new')";
mysql_select_db('churchinfo');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}
echo "<br> Entered data successfully\n";
mysql_close($conn);
?>
</body>
<?php
    $url = "?id=" . $cid  . "&res=" . $error;
    header('Location: photo.php'.$url);
?>
<script>
 location.href = "photo.php?" + <?php echo $error; ?> ; 
</script>
<br />
</body>
</html>
Dear Friends, 
This code is working in the localhost. Files also uploading to the folder. 
but When I trying in live server 
Headers already sent
error message is appearing. And file is also not at the /upload folder.
I read some articles in stackoverflow. But I have no idea to fix this error.
What should I do? 
Please help me.
 
     
     
     
     
    