Hi

Have taken the covers off your program. Love the look of your widget

However - I just want a simple file uploader - not an node->image uploader - essentially just something to replace the native Drupal Forms API file type but with support for a nice upload status bar.

I could then just use my own file_save_upload($fieldname, $validators, file_directory_path());

Is this possible with your module, and if so can you give me an example of how it would work?

thanks

Comments

alan d.’s picture

Just create a standard Drupal form, and use the upload_element element rather than the file element, then make sure you call the save function in your submit handler to tag the file as permanent. i.e.

$fid = upload_element_save($form_state['values']['myfile'], 'DA_DESTINATION_DIR', FILE_EXISTS_RENAME);

I'm a bit rusty as I haven't looked at the module for over a year now, but the above should produce either 0 or {files}.fid of the uploaded file. I guess you would be saving this value in the database? The only reference in the db via the module is in the standard Drupal files table. If this record is not needed, delete the row from the database using the fid returned above. [Personally, I wouldn't do this, but to provide a file upload that is completely outside of the Drupal system, deleting this record would be best.]

db_query("DELETE FROM {files} WHERE fid = %d", $fid);

The database is needed during form submission as this is used to track incomplete form submissions so that the temp files are deleted if the user never gets past the form validation stages.

southweb’s picture

Hi Alan

Thanks - your recommendation worked perfectly.

alan d.’s picture

Status: Active » Fixed

:)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.