<div><br>Hi All<br>I want to create a node and attach a file programatically in D7.<br>I have below code, it creates a node, but does not have any attachment in it.<br>Can somebody point out whats the wrong here.</div>
<div><br><strong><em><font color="#3333ff">create_node_attach_file($filename , $fid)<br>{<br>    $node = new stdClass();<br>    $node-&gt;type = &#39;page&#39;; <br>    node_object_prepare($node);</font></em></strong></div>

<p><strong><em><font color="#3333ff">    $node-&gt;language = LANGUAGE_NONE;  <br>    $node-&gt;title = &#39;Title - XYZ&#39;;<br>    $node-&gt;uid = 1;   </font></em></strong></p>
<p><strong><em><font color="#3333ff">    $absfilename = &#39;sites/default/files/&#39; . $user-&gt;uid . &#39;/&#39; . $filename&#39;;<br>    $filepath = drupal_realpath($absfilename);</font></em></strong></p>
<p><strong><em><font color="#3333ff">    $file = (object) array(<br>        &#39;uid&#39; =&gt; 1,<br>        &#39;uri&#39; =&gt; $filepath,<br>        &#39;filemime&#39; =&gt; file_get_mimetype($filepath),<br>        &#39;status&#39; =&gt; 1,<br>
        );</font></em></strong></p>
<p><strong><em><font color="#3333ff">    $file-&gt;new = true;<br>    $file-&gt;fid = $fid;</font></em></strong></p>
<p><strong><em><font color="#3333ff">    // Attach the file object to your node<br>    $node-&gt;field_resume[$node-&gt;language][0] = (array)$file;</font></em></strong></p>
<p><strong><em><font color="#3333ff">    // Prepare node for saving<br>    $node = node_submit($node);</font></em></strong></p>
<p><strong><em><font color="#3333ff">    //save the node<br>    node_save($node);  <br>                <br>}</font></em></strong></p>
<p>Thanks<br>Kamal<br></p>