Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload File Script
  • hello guys. I'm a beginner of this fuelphp. i just want to ask you guys to please give me some instructions, or steps on how to create a working upload here in fuelphp. tnx
  • I can't find the files that I uploaded in the directory. And what do you mean by php_fileinfo extension? Do I have to download it? I already use the PATH, but nothing happened.
  • If you don't get an exception, I guess the fileinfo extension is present. It is by default in 5.3+, but on Windows you need to install the .dll manually. Did you follow the documenation:
    - run process()
    - check for errors
    - if no errors run save() If there were any errors detected, nothing will be saved. The upload class doesn't to partial saves, unless you explicitly save a single uploaded file (which then must have no errors).
  • I followed the documentation, but I am not sure if the arrangement of the codes was correct. I get trouble in following the instruction, it's hard for me to follow because this is the first time that i used the fuelphp.
  • Seem ... no error appear but u couldn't find the uploaded file ....So, i think you forgot this in your form tag 'enctype'=>'multipart/form-data'
  • There's a full instruction in documentation. What problem did you encounter ? if you are using window, you will need php_fileinfo extension.
  • Hi, sorry if I'm interrupting, because I have the same problem when using Upload in Windows. I have no problem running the Upload in Ubuntu. And I'm using XAMPP 1.8.1.

    public function action_create() {
        if (Input::post()) {
          $val = Model_Member::validate('create');

          if ($val->run()) {
            $config = array(
                'path' => DOCROOT . DS . 'member'
            );
            Upload::process($config);
            if (Upload::is_valid()) {
              Upload::save();
              $file = Upload::get_files(0);

              $member = Model_Member::forge(array(
                          'nim' => Input::post('nim'),
                          'name' => Input::post('name'),
                          'gender' => Input::post('gender'),
                          'birth_place' => Input::post('birth_place'),
                          'birth_date' => Input::post('birth_date'),
                          'addr_home' => Input::post('addr_home'),
                          'addr_mlg' => Input::post('addr_mlg'),
                          'phone' => Input::post('phone'),
                          'photo' => $file['name']
                      ));
              if ($member and $member->save()) {
                Session::set_flash('success', e('Berhasil menambahkan anggota #' . $member->member_id));
                Response::redirect('admin/member');
              } else {
                Session::set_flash('error', e('Gagal menambahkan anggota'));
              }
            } else {
              $member = Model_Member::forge(array(
                          'nim' => Input::post('nim'),
                          'name' => Input::post('name'),
                          'gender' => Input::post('gender'),
                          'birth_place' => Input::post('birth_place'),
                          'birth_date' => Input::post('birth_date'),
                          'addr_home' => Input::post('addr_home'),
                          'addr_mlg' => Input::post('addr_mlg'),
                          'phone' => Input::post('phone'),
                      ));
              if ($member and $member->save()) {
                Session::set_flash('info', e('Berhasil menambahkan anggota #' . $member->member_id . ' tanpa menyertakan foto.'));
                Response::redirect('admin/member');
              } else {
                Session::set_flash('error', e('Gagal menambahkan anggota'));
              }
            }
          } else {
            Session::set_flash('error', $val->error());
          }
        }

        $this->template->title = 'Keanggotaan';
        $this->template->content = View::forge('admin/member/create');
      }

    Are there any mistakes in my code? Thank you in advance +
  • the error message is

    ErrorException [ Error ]: Call to undefined function Fuel\Core\finfo_open()

    COREPATH/classes/upload.php @ line 344
  • Your installation doesn't have the fopen extension installed.

    It must be part of the installation per default in PHP 5.3+. If you're on Windows, you must install the dll manually. If you're on your own machine, install it. If you use a hoster, kick him because he's using outdated compile scripts to make the PHP binaries.
  • Hey, I just found out how to solve this problem. It's not from the code, but the extension of php_fileinfo is not activated by default in XAMPP 1.8.1. Here is the way I solved this :

    1. Open php.ini in C:\xampp\php with your favorite editor (I use Notepad++ to open this file)
    2. Look for line 994  and remove the semicolon mark to activate the extension=php_fileinfo.dll
    3. Restart the apache
    4. Now you should be able to upload your file, don't forget to insert the enctype in your form :) +
  • That's what I wrote: "If you're on Windows, you must install the dll manually.".

    This requirement is also documented: http://fuelphp.com/docs/requirements.html
  • Yes, Harro, I think a little bit of explanation would be great :) +
  • If you have XAMP , Enable this dll 

    XAMP -> Config(Apache) - php.ini file 

    Search for php_fileinfo ( on notepad , ctrl+f)

    ;extension=php_fileinfo.dll 

    You can see above one 

    Enable it by removing ';' 

    So it become 

    extension=php_fileinfo.dll
  • @Zaaldian: I couldn't, I haven't touched any Windows in years, and never used XAMPP... ;)

    @sibinx7: thanks for clarifying!

Howdy, Stranger!

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

In this Discussion