allow upload/overwrite/edit files

radj - January 19, 2009 - 14:58
Project:Filebrowser
Version:HEAD
Component:Administrative Interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

this might be the biggest feature request ever:

allow uploading and overwriting files
also allow editing text files (like CSS or php files)

of course, there are 2 layers of permissions
first, whatever the server allows the drupal installation to touch/edit
next, admin permissions

now this would really make it a complete browser. ^_^

#1

Yoran - April 1, 2009 - 17:47

It's in the pipe, this will be the next feature I'll add I think.

#2

BENNYSOFT - April 2, 2009 - 11:44

now this would really make it a complete browser.

If you need this you can use the Web File Manager module. We don't need duplicates of existing modules.

#3

Yoran - April 2, 2009 - 14:07

We don't need duplicates of existing modules

Yep but we need both simple and complexe modules for the same task sometime ;-)

#4

cmgui - April 13, 2009 - 22:56

Hi Yoran

Thank you for contributing this wonderful module.

I also would like to see a File Upload to the current directory. That is, when user browser to a certain directory, the File Upload will upload a file to that directory.
And yes, automatic renaming of file if there is another file with the same name on the folder.
For example, if file1.txt already exists in the folder, rename the new file1.txt to file1_1.txt.
And yes, delete capability too. And create new folder. Manual renaming of file.
And it would be good if users can add the file description themselves instead of needed the admin to add it into descript.ion file on the server).

In short, a full fledged file manger.

Your module is better than the more powerful Ajax Web File Manager because it is integrated with
Drupal node system. Ajax Web File Manager is powerful but it is complicated and does not use Drupal node system and it is not possible to have a http link to a directory. You are on the right track!

Thank you once again and looking forward to your next release!

#5

cmgui - April 14, 2009 - 18:16

This is my little hack to have file upload.

in filebrowser.module

in function filebrowser_theme()

    ),
    'filebrowser_page_title' => array (
      'arguments' => array (
        'node' => NULL
      )
    ),
// hack 1
  'filebrowser_up' => array (
      'arguments' => array (
        'node' => NULL
      )
    ),

// hack 2
  'filebrowser_up_form2' => array (
      'arguments' => array (
        'form' => NULL
      )
    )

  );
}





in function filebrowser_theme()

   'filebrowser_page_title' => array (
      'arguments' => array (
        'node' => NULL
      )
    ),

// hack 3
  'filebrowser_up' => array (
      'arguments' => array (
        'node' => NULL
      )
    ),
   
// hack 4
  'filebrowser_up_form2' => array (
      'arguments' => array (
        'form' => NULL
      )
    )

  );
 
 
in function filebrowser_view

    drupal_set_title(theme('filebrowser_page_title', $node));

    $node->content['filebrowser']= array (
      '#value' => theme('filebrowser_dir_listing', $node, $data),
      '#weight' => 1,

     
    );
  }
// hack 5

  $node->content['filebrowser_up'] = array(
    '#value' => theme('filebrowser_up', $node),
    '#weight' => 9,
  );
 

  return $node;
}
if (!function_exists('endsWith')) {
  function endsWith($str, $sub) {
    return (substr($str, strlen($str) - strlen($sub)) == $sub);
  }
}




// hack 6
function theme_filebrowser_up( &$node ) {
// var_dump( $node );
return drupal_get_form('filebrowser_up_form2', $node);
}

// hack 7
function filebrowser_up_form2( $node ) {


  $form['#attributes'] = array("enctype" => "multipart/form-data");

// used the contributed module upload element instead of drupal file element at first
// but reverted to file element
  $form['file1'] = array(
//    '#type' => 'upload_element',
    '#type' => 'file',
//    '#title' => t('File'),
    '#size' => 30,
//    '#required' => TRUE,
//    '#default_value' => '',
//    '#file_validators' => array(
//          'file_validate_size' => array(16384),
//          'file_validate_extensions' => array('txt gif patch diff jpg jpeg'),
//        ),
    );

  $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit')
    );

return $form;
}


// hack 8 

function theme_filebrowser_up_form2( $form ) {
    $form['file1']['#prefix'] = '<div><table><tr><td>';
    $form['file1']['#suffix'] = '</td></tr></table></div>';

    $form['submit']['#prefix'] = '<tr><td>';
    $form['submit']['#suffix'] = '</td></tr></table></div>';

return drupal_render($form);

}

// hack 9
function filebrowser_up_form2_submit( $form, &$form_state ) {

$temp1 = drupal_get_breadcrumb();
$temp0 = array_shift( $temp1 );
$temp0 = array_shift( $temp1 );
$c1 = count( $temp1 );

for ( $i=0; $i < $c1; $i++ ) {
  $temp1[$i] = substr( $temp1[$i], strpos($temp1[$i],'>')+1, strrpos($temp1[$i],'<')-strpos($temp1[$i],'>')-1 );
}

$temp2 = implode( '/', $temp1 );

$filesystemfolder = file_directory_path() . "/" . $temp2;


//   if ( $form_state['values']['file1'] ) {
//       $file1_id = upload_element_save($form_state['values']['file1'],$filesystemfolder,FILE_EXISTS_RENAME);
//   }   

     $validators = array();

     if ( $file = file_save_upload('file1', $validators, $filesystemfolder ) ) {
          drupal_set_message(t('File successfully uploaded.'));
     }
     else
     {
          drupal_set_message(t('Upload failed.'));
     }        

}
 

#6

cmgui - April 15, 2009 - 22:57

slightly improvement -

function filebrowser_up_form2( &$form_state = NULL, $node ) {
// note &$form_state = NULL is required; otherwise it won't work
..
..
$form['file_path1'] = array(
'#type' => 'hidden',
'#value' => $node->file_path,
);

--

and in function filebrowser_up_form2_submit(

// $filesystemfolder = file_directory_path() . "/" . $temp2;

$filesystemfolder = $form_state['values']['file_path1'] . "/" . $temp2;

----

i'm still hoping that Yoran will incorporate upload file, delete/rename file, add/edit/delete file description (meta-data) and create/delete/edit folders in the filebrowser view.
my hack is not 100% tested.

this Filebrowser module is great! everybody drupal contributed module should follow this example of using drupal node system.

#7

Yoran - April 20, 2009 - 00:19
Status:active» fixed

Sad you didn't send me a message about this, I was working exactly on this (RC8). Now upload normaly works and you can also rename the uploaded file.

#8

Yoran - April 20, 2009 - 00:22

By the way I totaly aggree with your vision of filebrowser vs WebFM. In that vision I tried to extend this node way of doing this by directly loading data (files, path,etc.) in the node object.

#9

System Message - May 4, 2009 - 00:30
Status:fixed» closed

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

#10

mauricemengel - October 22, 2009 - 15:31
Status:closed» active

What about the edit and the delete function? As far as I can see, it is not possible at the moment to either overwrite or change or delete a file. Is there any progress to be expected soon? At least a delete would be nice. Thanks!

#11

mauricemengel - October 25, 2009 - 19:16

Maybe someone is interested in my workaround: I use webfm with access only to moderators for upload and renaming and display/download for everybody with filebrowser.

 
 

Drupal is a registered trademark of Dries Buytaert.