I have content type with Photos ImageField. I need to create some moderation view to show all photos and "delete" link to delete appropriate photo. How can I programmatically delete value from CCK field (in general not only ImageField but any field type)?
You will need to check the ImageField array to see what needs to be changed but for D6 but it should be something like the below:
$node = node_load($nid); $node->field_photo['value'] = NULL; node_save($node);
Just change the field name to what you are using and change the $nid to the node id #.
WestieUK has a correct general expression. However, the vague question presents two potential cases for Filefield/Imagefield here:
- Delete all references to that file from all nodes ->
- Delete only that node's reference to the file -> Use WestieUK's method.
If there never are multiple node associations for the files in your structure (usual behavior in Filefield/Imagefield), method #1 is safe and simple to use for case #2 as well.
If the file is no longer referenced, do not forget to also remove the entry from the file tables and delete the file from disk with