Warning: unlink() expects parameter 2 to be resource, string given in drupal_unlink() (line 2194 of /includes/file.inc) I'm using drupal_unlink() for deleting my files, but don't know why I'm keep on getting this error repetitively?

Warning: unlink() expects parameter 2 to be resource, string given in drupal_unlink() (line 2194 of /includes/file.inc).

&lt;?php
$query = db_select('temp_container_mapping', 'c');
$query-&gt;innerJoin('temp_image_holder', 'i', 'i.nid = c.nid');
$query-&gt;fields('c', array('cid', 'nid', 'container', 'users_list', 'api_key', 'regions', 'abbreviative'));
$query-&gt;fields('i', array('id', 'nid', 'image_path', 'image_style', 'final_image_name_path'));
$query-&gt;condition('i.image_style', $param_image_style, '=');
$query-&gt;range(0, 10);
$entries = $query-&gt;execute()-&gt;fetchAll(PDO::FETCH_ASSOC);

if (!empty($entries)) {
  foreach($entries as $value) {

    $container_id = $value['cid'];
    $nid = $value['nid'];
    $id = $value['id'];
    $image_path = $value['image_path'];
    $image_style = $value['image_style'];
    $final_image_name_path = $value['final_image_name_path'];
    $container = $value['container'];
    $users_list = $value['users_list'];
    $api_key = $value['api_key'];
    $regions = $value['regions'];
    $abbreviative = $value['abbreviative'];

    //Establish Connection with server
    $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username'=&gt;$users_list, 'apiKey'=&gt;$api_key));

    $service = $client-&gt;objectStoreService('cloudFiles', $abbreviative);
    $container = $service-&gt;getContainer($container);


    $temp_arr = explode("/", $final_image_name_path);
    $end_element = end($temp_arr);

    try {
      $file = $container-&gt;getObject($end_element);
      $fileExists = true;
    } catch (Exception $e) {
      $fileExists = false;
    }

    if ($image_style == "245") {
      $image_style_w = "168";
    } else {
      $image_style_w = $image_style;
    }

    $style = $image_style_w."w_".$image_style."h";
    $display_style[$image_style] = image_style_load($style);
    image_style_create_derivative($display_style[$image_style], $image_path, str_replace("rcf:///", "public:///rackspace/", $final_image_name_path));

    if ($fileExists) {
      //File is ther needs to overwrite
      $file-&gt;setContent(fopen('sites/default/files/rackspace/'.$end_element, 'r+'));
      $file-&gt;update();
      print 'existing overwrite&lt;br&gt;';
    } else {
      //New file just to upload
      $container-&gt;uploadObject($end_element, fopen('sites/default/files/rackspace/'.$end_element, 'r+'), array());
      print 'new one&lt;br&gt;';
    }

    drupal_unlink("public:///rackspace/", $final_image_name_path);
  }
}
?&gt;
probably a typo ',' -> '.'
drupal_unlink("public:///rackspace/" . $final_image_name_path);