How do I get a link to an image CCK in Drupal 7 in the node view? If I do this:

print_r($node);


I get this:

 [field_main_photo] =&gt; Array
    (
        [und] =&gt; Array
            (
                [0] =&gt; Array
                    (
                        [fid] =&gt; 86
                        [uid] =&gt; 1
                        [filename] =&gt; 01.jpg
                        [uri] =&gt; public://01.jpg
                        [filemime] =&gt; image/jpeg
                        [filesize] =&gt; 28385
                        [status] =&gt; 1
                        [timestamp] =&gt; 1409510061
                        [alt] =&gt; 
                        [title] =&gt; 
                        [width] =&gt; 600
                        [height] =&gt; 400
                    )

            )

    )


How can I turn that information into a usable link? I want to know how to link directly to 01.jpg?
You want to use the Drupal link function l()  for this.

  $link_html = l('some cool link text', $node-&gt;field_main_photo['und']['0']['uri'];


then you can either print that $link_html variable OR you can return it some other function will be rendering it.

Bonus:
You can replace the 'some cool link text' with the name of the file by using this:

$node-&gt;field_main_photo['und']['0']['filename']


So that would give us:

$link_html = l($node-&gt;field_main_photo['und']['0']['filename'], $node-&gt;field_main_photo['und']['0']['uri'];


Make sense?

Also... print_r() can often ve difficult to parse through. I recommend that you enable the DEVEL module and instead do the following:

dpm($node);


This will render the node on the page in a manner that you can click through and inspect each element and array and object. Even better, you can double click the value and the variable path to that value shows up for you to copy and paste into your code.

I hope this helps! :-)