在服务器中保存图像时出错

my php script looks like this:

<?php

$con=mysqli_connect('mysql.hostinger.in','username','password','databasename');

$data = $_POST['img'];
$name=$_POST['name'];

$data = base64_decode($data);
$file = 'images/'. md5($name) . '.png';
if (file_exists($file)) {
            unlink($file);

         } 
$success = file_put_contents($file,$data);
echo "success";


?>

There are 2 problems:

  1. the images are saved in server but have size is zero?
  2. when i am putting large Image string as parameter the error shows up "Size of a request header field exceeds server limit."

please help me out what should i do? and for testing purpose i have converted Image to base64 string via online site.