Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload file name empty?
  • Hi, I managed to upload files through a file input, but I can't seem to get the name of the file. Here is the code:
    if(Sentry::check())
      {
       if (Input::method() == 'POST'){
        $config = array(
         'path' => DOCROOT.DS.'assets/img/front/users/temp',
         'max_size' => 51200,
         'randomize' => true,
         'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
        );
    
        Upload::process($config);
    
        if (Upload::is_valid())
        {
         Upload::save();
        
         $user = Model_Users::find_by_id(Sentry::user()->get('id'));
         $user->picture = Upload::get_files(0)->name;
         $user->save();
        }
    
        // and process any errors
        foreach (Upload::get_errors() as $file)
        {
         Session::set_flash('error', 'Invalid file!');
         Response::redirect('/users/settings');
        }
        Session::set_flash('success', 'Profile picture changed!');
        Response::redirect('/users/settings');
       }
       $this->template->title = "Settings";
       $this->template->content = View::forge('users/settings');
      } else {
       Log::warning('Following person did not have authorisation - ('.$_SERVER['REMOTE_ADDR'].')');
       Session::set_flash('error', 'Access restricted!');
       Response::redirect('/');
      }
    

    So as you can see I use a random name for the uploaded picture.
    The file gets uploaded in the right folder but for some reason
    Upload::get_files(0)->name;
    

    gives me an empty string. Any ideas why? Regards
  • get_files() doesn't return an object?
  • sorry, read between the lines, its a multi dimensional array -.- thanks

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion