Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Simple upload script failing.
  • Here is what my controllers look like:
    public function action_submit() {
        $this->template->title = 'Pages » Submit';
        $this->template->content = View::forge('pages/submit');
      }
    
      public function action_upload() {
        $this->template->title = 'Pages » Upload';
        $this->template->content = View::forge('pages/upload');
        $config = array(
          'path' => DOCROOT.DS.'files',
          'randomize' => true,
          'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
        );
    
        Upload::process($config);
        if (Upload::is_valid()) {
          Upload::save();
        }
    
      }
    

    And my views:
    <h3>Submit</h3>
    <?php
    echo Form::open('pages/upload');
    echo Form::file&#40;'file'&#41;;
    echo '<br />';
    echo Form::submit('submit');
    echo form::close();
    ?>
    
    <h1>upload</h1>
    

    And I'm getting these errors: Notice! ErrorException [ Notice ]: Undefined variable: key COREPATH/classes/upload.php @ line 424: 423: // and add the message texts
    424: foreach (static::$files[$key] as $e => $error)
    425: {
    Notice! ErrorException [ Notice ]: Undefined index: COREPATH/classes/upload.php @ line 424: 423: // and add the message texts
    424: foreach (static::$files[$key] as $e => $error)
    425: {
    Warning! ErrorException [ Warning ]: Invalid argument supplied for foreach() COREPATH/classes/upload.php @ line 424: 423: // and add the message texts
    424: foreach (static::$files[$key] as $e => $error)
    425: {
    Notice! ErrorException [ Notice ]: Undefined variable: key COREPATH/classes/upload.php @ line 424: 423: // and add the message texts
    424: foreach (static::$files[$key] as $e => $error)
    425: {
    Notice! ErrorException [ Notice ]: Undefined index: COREPATH/classes/upload.php @ line 424: 423: // and add the message texts
    424: foreach (static::$files[$key] as $e => $error)
    425: {
    Warning! ErrorException [ Warning ]: Invalid argument supplied for foreach() COREPATH/classes/upload.php @ line 424: 423: // and add the message texts
    424: foreach (static::$files[$key] as $e => $error) What am I doing wrong?
  • Your form doesn't have the enctype needed to upload files. The errors are a result of not capturing the fact that no files were uploaded. I've fixed that.
  • Oh okay cool thanks. How do I add the enctype to my form?
  • You can add it when you open the form.
    echo \Form::open(array('enctype' => 'multipart/form-data'));
    

    Btw, you don't need to specify the form action if it is the same as the current uri.
  • You guys rock, thanks for all the help. I've added the enctype, and I'm still getting the same errors. Any other ideas?
  • Got it working. No errors, but the file doesn't actually upload. The directory is empty. Currently trying to process any errors that may be there. I'll keep the thread updated.

Howdy, Stranger!

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

In this Discussion