<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="sans-serif">Hi Randy,<br>
<br>
I had a look at the File API handbook you linked to, and I guess
file_usage_add() is what I need, however I tried implementing it
and no new records are showing in the {file_usage} table...<br>
Here's the code: file_usage_add($uploaded_file, 'block_icons',
'block', $bid);<br>
(I got $bid from the {block} table)<br>
<br>
My module allows users to upload an image to each block on the
site, so I created my own database table where each block that has
an image associated with it is listed.<br>
If I don't need to store the path to the images anymore, I'm
assuming file_usage_add() does that for me somehow...?<br>
<br>
</font><br>
On 02/05/11 13:13, Randy Fay wrote:
<blockquote
cite="mid:BANLkTintPk6RDygdsXqBO0pS8-xiMJK5+Q@mail.gmail.com"
type="cite">I'm a bit baffled why you'd consider accessing the
database directly - you should be using the file API.<br>
<br>
File API handbook section is at <a moz-do-not-send="true"
href="http://drupal.org/node/555118">http://drupal.org/node/555118</a>
<br>
<br>
You should use the File API to create managed or unmanaged file
entries, and not worry more about how they are stored in the db.<br>
<br>
A module that might help you is <a moz-do-not-send="true"
href="http://drupal.org/project/filefield_sources">http://drupal.org/project/filefield_sources</a>.
In fact, it might already do everything you need. Anyway, it
allows you to add a file from any source.<br>
<br>
It *is* complicated trying to allow access to a file that is not
in your public or private files section. The idea of having
drupal:// didn't get in.<br>
<br>
-Randy<br>
<br>
<div class="gmail_quote">On Sun, May 1, 2011 at 8:21 PM, Peter
Anderson <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:list@panda.id.au">list@panda.id.au</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000"> <font
face="sans-serif">Hi everyone,<br>
<br>
I'm upgrading my D6 module to D7 and am trying to work out
the best way to implement the new File API...<br>
My module allows users to either upload a file from their
computer, or enter the relative path of a file already on
the server (e.g. /sites/default/themes/...). The relative
path to this file is then stored in the DB.<br>
<br>
I'm not sure what to store in the database in the D7
version: the file URI (public://my_file.png) or the
relative path as per the D6 version
(/sites/default/files/my_file.png).<br>
The reasons I'm not sure are as follows:<br>
- Storing the File URI seems to be the obvious choice as
that seems to be the default now<br>
- But how would I allow users to enter the path of a file
already on the server in, say, their theme folder?<br>
- Storing the relative path is how I used to do it, so is
easier<br>
- But then how do I change a relative path to a File URI
when required (e.g. by the image_style_url() function)?<br>
<br>
Any assistance or advice would be much appreciated!<br>
</font>
<pre cols="72">--
Kind regards,
Peter Anderson.
<a moz-do-not-send="true" href="http://panda.id.au" target="_blank">http://panda.id.au</a>
</pre>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
Randy Fay<br>
Drupal Module and Site Development<br>
<a moz-do-not-send="true" href="mailto:randy@randyfay.com">randy@randyfay.com</a><br>
+1 970.462.7450<br>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Kind regards,
Peter Anderson.
<a class="moz-txt-link-freetext" href="http://panda.id.au">http://panda.id.au</a>
</pre>
</body>
</html>