title: File name too long while uploading image in database
body: <p>I have written a line of codes to upload an image in the database, however, trying to upload image gives me this error</p>
  
  <blockquote>
    <p>File name too long</p>
  </blockquote>
  
  <p>Following is my code to upload an image to database:</p>
  
  <pre><code>if($_SERVER['REQUEST_METHOD']=="POST")
      {
        $pid          = rand(1000,9000);
        $title        = $_POST['title'];
        $descpt       = $_POST['description'];
        $push         = isset($_POST['send_push']) ? $_POST['send_push'] : "";
        $feature_image = array();
        $fy           = $_POST['fy'];
  
        if(empty($title) || empty($descpt) || empty($fy))
        {
            array_push($this-&gt;errors, MEND_FIELD_ERROR);
            return;
        }
  
        if(!empty($_FILES['feature_image']['name'][0]))
        {
            $image = $_FILES['feature_image'];
            $allowed_ext = array('jpeg','jpg','png','pdf','docx');
            $allowed_size = 20000000;
  
            foreach($image['name'] as $pos=&gt;$image_name)
            {
                $dir = "./cdn/uploads/notice/".$title;      
                $tmp = $image['tmp_name'][$pos];
                $img_size = $image['size'][$pos];
                $img_error = $image['error'][$pos];
                $img_ext = explode('.', $image_name);
                $img_name = $img_ext[0];
                $img_ext = strtolower(end($img_ext));
  
  
                if(in_array($img_ext, $allowed_ext))
                {
                    if($img_size &lt;= $allowed_size)
                    {
                      if(!file_exists($dir))
                      {
                          mkdir($dir);
                      }
                      $image_new_name = $img_name.'$$'.uniqid('', true).'.'.$img_ext;
  
                      $upload_destination = $dir.'/'.$image_new_name;
                      if(move_uploaded_file($tmp, $upload_destination))
                      {
                          array_push($feature_image, $image_new_name);
                      }
                      else
                      {
                          array_push($this-&gt;errors, $img_error);
                          return;
                      }
  
                    }
                }
                else
                {
                  array_push($this-&gt;errors, $img_ext.' is not an allowed file extension.');
                  return;
                }
            }
        }
  
        $s_feature_image = json_encode($feature_image, JSON_UNESCAPED_UNICODE);
  
        $statement = $this-&gt;db-&gt;prepare("INSERT INTO `notice` (`pid`,`title`,`descpt`,`date`,`photo`,`fy`)
        VALUES (?,?,?,?,?,?)");         
        if($statement-&gt;execute([$pid,$title,$descpt,DAT, $s_feature_image, $fy]))
        {
          if($push == "checked")
          {
  
              $descpt = strip_tags($descpt);
              $tek = array("message"=&gt;$descpt,"title"=&gt;$title);
  
              $tokens = $this-&gt;getTokens();
              $this-&gt;push_notification($tokens,$tek);
  
          }
          ExitThis::send_to(URL.'notice?id='.$pid);
  
        }
        else
        {
            array_push($this-&gt;errors, DATABASE_ERROR);
            return;
        }
      }
  </code></pre>
  
  <p>Is it because of permission issue or something else? If so, what is causing me this problem and how do I fix this?</p>