Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorkrzyzak
    • CommentTimeFeb 25th 2008 edited
     

    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
    • CommentTimeFeb 25th 2008 edited
     

    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
    • CommentTimeFeb 25th 2008
     

    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 :)

Add your comments
    Username Password
  • Format comments as