Topic: Create folder

I have a code to create a folder but I get the same name and if I leave it blank does not work.

<!-- Filesmanager_create_folder-->
    <?php
        $folder = " name of folder  ";
        if (Request::post('folderName')) {
            if (Dir::exists( '../public/uploads/'.$folder )) {
                echo '<div class="alert alert-error">
                            <button type="button" class="close" data-dismiss="alert">x</button> 
                            <p> File '. $folder.' exists</p>
                        </div>';
            }else{  
                        Dir::create( '../public/uploads/'.$folder ); 
                        Request::redirect($site_url.'admin/index.php?id=filesmanager&path='.$folder);  
            }
        }    
        echo (
        '<div class="well">'.
            Form::open(null, array('enctype' => 'multipart/form-data')).
            Form::input('text', ' ', array('type' => 'text', 'name' => 'folderName')).Html::br().
            Form::submit( 'folderName', __('Create folder', 'filesmanager'), array( 'class' => 'btn default btn-small')).
            Form::close()
        .'</div>'
        );
?>
<!-- /Filesmanager_create_folder-->
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

>> I get the same name and if I leave it blank does not work.
sorry I cant undrestand)) please explain)

Re: Create folder

I will try to explain sorry for my english.

I want create a gallery  plugin  in backend and   i need create a folder but  the name  variable  of  the folder  $folder = ' '   if left blank, not  works but if I write $ folder = 'example', if it works

<?php        
 $folder = " example_folder ";    
    if (Request::post('folderName')) {    
        if (Dir::exists( '../public/uploads/'.$folder )) {        
            echo '<div class="alert alert-error">
                <button type="button" class="close" data-dismiss="alert">x</button> 
                <p> File '. $folder.' exists</p>
                </div>';    
        }else{  
           Dir::create( '../public/uploads/'.$folder ); 
           Request::redirect($site_url.'admin/index.php?id=galleries&path='.$folder);  
        }
    }                
  echo (
    '<div class="well">'.
       Form::open(null, array('enctype' => 'multipart/form-data')).
       Form::input('text', $folder,   array( 'type' => 'text', 'name' => 'folderName')).Html::br().
       Form::submit( 'folderName', __('Create folder', 'galleries'), array( 'class' => 'btn default btn-small')).
       Form::close()
    .'</div>'
    );    
?>

and another question.
to save a text this is correct

     //  create title
     $photoTitle = new Table('photo_title');       
     if (Request::post('photoTitle')) {       
       Table::create('photo_title', array('text', 'title'));    
     }
     //  create content-text    
     $photoText = new Table('photo_text'); ;    
      if (Request::post('photoText')) { 
          Table::create('photo_title', array('text', 'textarea'));    
      }    
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

Preview Project

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

nakome, I am trying to reproduce your code in my local Monstra, but I cant help for the moment. If you can. Please provide this plugin to me. Than I will install it localy and test it...


   //  create title
     $photoTitle = new Table('photo_title');       
     if (Request::post('photoTitle')) {       
       Table::create('photo_title', array('text', 'title'));    
     }
     //  create content-text    
     $photoText = new Table('photo_text'); ;    
      if (Request::post('photoText')) { 
          Table::create('photo_title', array('text', 'textarea'));    
      }    

This is works fine ? I think it's not works fine....


Variant 1

When you create a new folder(gallery) You may create a new table for this gallery.

Table::create('folder_name', array('filename', 'title', 'description'));

Add new records to this table, when you upload a new images to this folder(gallery)

$table = Table::get('folder_name');
$table->insert(array('filename'=>'uploaded file name here', 'title'=>'', 'description' => ''));

Updating

$table = Table::get('folder_name');
$users->updateWhere('[filename="'.$filename.'"]', array('title'=>$title, 'description'=>$description));

Select records from current gallery

$table = Table::get('folder_name');
$records = $users->select(null, 'all'); // select all records
// Loop through them
foreach($records as $record) {
  // And you will get 
  echo $record['filename'];
  echo $record['title'];
  echo $record['description'];
}

Delete image from folder(gallery)

$table = Table::get('folder_name');
$table ->deleteWhere('[filename="'.$filename.'"]');

6 (edited by nakome 2012-09-28 21:40:36)

Re: Create folder

This is a plugin 

I'm Monstra Student Newbie smile

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

updated
/galleries.admin.php
/views/backend/index.view.php

http://rghost.ru/40632755

Re: Create folder

Thank you i will study the code smile

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

This goes out for me whenever I try to guard the table.

Call to a member function insert() on a non-object

That I do badly?

             // Upload file
            if (Request::post('upload_file')) {
                    $folder = Security::safeName(Request::post('folderName'));
                if ($_FILES['file']) {
                    if ( ! in_array(File::ext($_FILES['file']['name']), $forbidden_types)) {        
                        move_uploaded_file($_FILES['file']['tmp_name'], $files_path.Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), '-', true).'.'.File::ext($_FILES['file']['name']));
                        $table = Table::get( $folder );
                        $table->insert(array('filename'=>'uploaded file name here', 'title'=>'', 'description' => ''));                                                                
                       // Redirect  
                        Request::redirect($site_url.'admin/index.php?id=galleries&path='.$path);                    
                    }
                }
            }
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

Sorry...

Must be:

$table = new Table('table_name_here');

Re: Create folder

The table is already created when I create a folder, is what I call the table and insert data.

Something I am doing wrong.

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

You can write me an example of how to save a text in the database.
Thanks

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

nakome, I will try to help you today after Work.

Re: Create folder

Thanks Awilum.

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

nakome, I download the lastest version of your plugin from Github and there is a problem:
https://github.com/nakome/galleries
and
https://github.com/nakome/galleries/tree/master/assets

What is that ? What changes are newest ? Please push latest changes on GitHub.

Re: Create folder

You can install SmartGIT http://www.syntevo.com/smartgit/index.html - its free

Re: Create folder

In the night i see the program, thanks


galleries.zip

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

I have update "Upload file"

            // Upload file
            // -------------------------------------    
            if (Request::post('upload_file')) {
                if ($_FILES['file']) {
                    if ( ! in_array(File::ext($_FILES['file']['name']), $forbidden_types)) {        
                        // Get real current folder name
                        $current_folder_name = Security::safeName($current[count($current)-2]);
                        $gallery = new Table($current_folder_name);
                        $gallery->insert(array('filename' => '',
                                               'title' => Request::post('title'),
                                               'description' => Request::post('description')));
                        move_uploaded_file($_FILES['file']['tmp_name'], $files_path.Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), '-', true).'.'.File::ext($_FILES['file']['name']));
                        Request::redirect($site_url.'admin/index.php?id=galleries&path='.$path);                    
                    }
                }
            }
         

Re: Create folder

Thank you, I take a look

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

I have a problem in line 162 Github

Call to a member function updateWhere() on a non-object

Why? sad

What more I is costing is view and update the database.

Well I am slowly understanding the framework.

Little by little it is running

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

21 (edited by nakome 2012-10-06 14:31:50)

Re: Create folder

I'm going to rewrite the plugin and use idiorm I think much better.

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Create folder

nakome, 5 - 7 October I was on Aikido Aikikai Seminar and I dont have access to my computer and internet... If you have some  more questions to me, you are welcome. smile