I'd like to call a php function I've written upon each successful file upload. My function creates a thumbnail image from a video clip. I'm using CCK to define a custom content type which stores a video title, the video file, and a thumbnail image.

I've been reading the documentation, and scouring the drupal code. I believe the approach would be to alter the 'upload_nodeapi' function in some manner.

Any pointers would be greatly appreciated, it's tough for me to understand the system by reviewing the code and the api. I feel like it could take weeks of review before I'm comfortable making changes to the code.

Comments

ufku’s picture

you may use your own hook_nodeapi in a custom module. before the node insertion you can check if there is an uploaded file($_FILES['yourfile']) and execute your function.

drawk’s picture

Can anyone verify that this works with CCK types?

My attempts with hook_submit and hook_nodeapi don't seem to get called. Using hook_form_alter with CCK, however, does work fine.

---
www.whatwoulddrupaldo.org

ufku’s picture

if your custom module comes after cck in alphabetical order, cck runs first and does what it does before your module. change your modules name in order to take the precedence.

--
Geneticists from METU

drawk’s picture

Thanks ufku. I renamed my module to "aaa" and gave it a try, but still nothing was happening. Took another look at my code and realized I needed to use my_form_name_submit rather than aaa_submit.

Now the hook_submit code is being triggered, but I have the new problem that nothing is actually being submitted. If I create new content of that type, when I click on submit, I just end back up on the create node page with nothing having been submitted.

How do I go about calling whatever "parent" code is necessary so that I can do my thing in hook_submit and pass it back up the chain so that the node actually gets submitted?

---
www.whatwoulddrupaldo.org

ufku’s picture

use nodeapi hook to make insertions unless your module is the form creator.

--
Geneticists from METU

ymmatt’s picture

From what I can tell I'm attempting to do the same thing as posted here, however I am unsure where to put my code.

I have some custom functions that I would like to run on the submission of a new node.

The timing has to be right, I need to have the new node $nid, as well as be able to change a variable in this node.

Can anyone help?

Full description of my dilemma here