I am using managed_file in Drupal 7 for my custom module. Other than the form api and managed_file, I'm using my own custom tables for this module.
This will eventually be used on shared hosting via Dreamhost, so the requirements of using PECL extensions are probably not available at this answer suggests.
The behavior I want is when the file is uploaded by clicking the "upload" button, I at least want the image file to be a link that appears to indicate to the user that the file is uploaded. When I left the default #progress_indicator in place, the AJAX indicates it never uploads. However, this is false as I can see the file in managed_file table in the db.
I've looked through several searches for this and this is the form that I've come up and I cannot see what I'm doing wrong.
$item is the result of a database call of the previous object. Its genesis was derived from a post jaypan provided.
$form['#item'] = $item; dpm($item); => //every attribute to the sponsor object in the database. $uri = isset($item->logoFileID) ? fetch_name('file_managed', 'uri', 'fid', $item->logoFileID) : ''; $uri = isset($item->logoFileID) ? fetch_name('file_managed', 'uri', 'fid', $item->logoFileID) : ''; dpm($uri); => 'public://logos/myfile.gif' //to show valid return of $uri dpm($item-logoFileID); => 'public://logos/myfile.gif' $form['logoFileID'] = array( '#title' => 'file key', '#type' => 'hidden', '#default_value' => $item->logoFileID, ); $form['logo_fid'] = array( '#type' => 'managed_file', '#title' => t('Logo'), '#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'), '#upload_location' => 'public://logos/', '#progress_indicator' => 'none', '#default_value' => $file->uri, );
As I said, managed_file does save the file and returns an fid that I save with the sponsor record. The behavior I have gotten in this module is that the filename was showing in this part of a form, that when clicked in Drupal shows a popup modal of the image. My question is how do I get this back link back to appear in the form to show the user it has been uploaded?, thx sam