Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorkrzyzak
     

    Hi. I'm quite new in akelos. I'm trying to create file (in fact: image) upload script. I've got problem with passing file content to Ak::file_put_contents() function. My view:

    <%= start_form_tag {'controller'=>'panel'}, {'enctype'=>'multipart/form-data'} %> <h1>Dodaj pracę</h1> <label for="type">Typ</label><input id="file_type" type="file" name="file_type" /><br /> <label for="screen">Zrzut</label><input type="file" id="screen" name="screen" /><br /> <input type="submit" name="add" value="Wyślij" /> <?php echo $form_tag_helper->end_form_tag() ?>

    My controller:

    Ak::debug($this->params['screen']); if($this->params['file_type']){ $type= explode('.',$this->params['file_type']['name']); Ak::file_put_contents('works/'.time().'.'.$type[1],$this->params['file_type']); } $type= explode('.',$this->params['screen']['name']); Ak::file_put_contents('works/'.time().'_t.'.$type[1],$this->params['screen']); $this->redirectTo(array('controller'=>'panel')); file is created, however, content is... text, simply- it`s collection of data, simmilar as in Ak::debug($this->params['screen']); . How can I pass real file content(jpeg file) ?

    Sorry for my language errors, it`s not my native language.

    •  
      CommentAuthorfrancois
     

    Hello krzyzak,

    I got the same issue and finally i've used the native php function. Here a sample :

    $content is your screen in your exemple

    protected function uploadFile($file_name, $content, $content_dir){
    
    
        $tmp_file = $content['tmp_name'];
    
        if( !is_uploaded_file($tmp_file) )
        {
            $this->flash['error'] = Ak::t("The file can't be uploaded");
            $this->redirectTo(array('controller'=>'page'));
        }
    
        if( !move_uploaded_file($tmp_file, $content_dir.DS.$file_name) )
        {
            $this->flash['error'] = Ak::t("The file can't be moved");
            $this->redirectTo(array('controller'=>'page'));
        }
    
    }
    
    • CommentAuthorkrzyzak
     

    o.0 native php functions ? ehh, I'm using framework to avoid this situation. We should open new ticket on akelos bugtracker- however, I'll wait for developer's answer :)

    • CommentAuthorraiho
     

    i've the same problem and not work the native php functions too!! Can help me someone? this is the code:

    file: import.tpl

    <h2>_{Importing Addressbook}</h2> <?php echo $form_tag_helper->start_form_tag(array('action'=>'import'),array('enctype'=>'multypart/form-data')) ?> <?php //echo $controller->renderPartial('form') ?> <?php echo $form_tag_helper->file_field_tag('importFile') ?>
    <?php echo $addressbook_helper->cancel()?> <?php echo $addressbook_helper->save() ?> <?php echo $form_tag_helper->end_form_tag() ?>

    file: addressbook_controller.php

    function import(){ if($this->Request->isPost() && !empty($this->params['importFile'])){ print_r($_FILES); echo '
    '; print_r($this->params['importFile']); echo '
    '; $handle = fopen($this->params['importFile']['name'], 'r');
    } }

    this is the output:

    Array ( ) RUBRICA.csv Warning: fopen(RUBRICA.csv) [function.fopen]: failed to open stream: No such file or directory in /var/www/rubrica3/app/controllers/addressbook_controller.php on line 91

    So pay attemption: 1) $_FILES is empty!!!! why??? 2) $this->params['importFile'] is not a array but has the name of file when it would be $this->params['importFile']['name']... 3) then obviously the file .cvs not exists!!

    what's wrong?? i think would be a framework config error...

    • CommentAuthorinsanet
     
    @raiho: usually when $this->params['importFile'] is not an array and is just the name of the file, is because the 'enctype' is missing or wrong. so is this a typo or error? --> wrong: 'multypart/form-data' , good: 'multipart/form-data'
    • CommentAuthorraiho
     
    ohhh my GOD!!!! It's true!!! I lose one day of work behind this 'Y' :S
    Now it work... I fixed it.
    Insanet... tnx very very much nice job!! ;)