I have a file stored in the drupal file table. I need to get a $file object to save as a CCK field. How can I get $file object out of the file table in the DB?
3 Answers
1
votes
If you know the ID of the file, you could just use a query
$results = db_result(db_query("SELECT * FROM {files} WHERE fid = %d", 3));
You can of course alter the query to match your known information.
Depending on your result, you may also want to use db_fetch_array or db_fetch_object.
Then you can use $file = field_file_save_file($path, $validators, $drupal_destination) to save if with the help of CCK FileField.
Now you can use $file array to store as CCK Field.
0
votes
0
votes
Maybe not the best option, but I use field_file_load(). You might have to cast returned file to objects:
$file = (object)field_file_load($fid);