file upload / Help Please!

file upload

my form

<form enctype="multipart/form-data" method="POST" action="files.php" id="form_new_record">
<label>Titlu:</label><br /><input name="titlu" type="text"  id="required" accept="true" mask="email" value="'.$News->prepareTitlu().'" class="text" /><br /><br />
<label>Descriere:</label><br /><textarea name="descriere_old" accept="true" style="width:100%" id="descriere_new">'.fHTML::decode($News->prepareDescriere()).'</textarea><br />
<label>Data:</label><br /><input name="data" id="required" accept="true" type="text" class="datepicker" value="'.$News->prepareData().'" /><br /><br />
<label>Eticheta:</label><br /><input name="media" type="file" />
<input name="id" type="hidden" value="'.$News->prepareIdArticol().'" /><br /><br /><br />
<input name="token" type="hidden" value="'.fRequest::generateCSRFToken().'" />
 
<input type="submit" value="Submit"  id="new_record" />
</form>

my php :

try {
    $uploader = new fUpload();
    $uploader->setMaxFileSize('2MB');
    $file = $uploader->move('../../_media/galerie/', 'media');
        
    $News->setActiv(1);
    $News->populate();
    $News->store();
        
} catch (fExpectedException $e) {
    echo $e->getMessage();    
}

must mentioned that this form is created on the fly but have that multipart in form tag.

firebug response:

{doc_root}/admin/news/server.php(389): fUpload->move('../../_media/ga...', 'media')
{doc_root}/admin/inc/flourish/fUpload.php(211): fUpload::check('media')
{doc_root}/admin/inc/flourish/fUpload.php(42)
Missing enctype="multipart/form-data" attribute in form tag

i use jquery for post data( this plugin can handle file uploads ). So.. other field goes right for data base input, but for file upload i get this problem, have someone an idea what happening?

  • Message #359

    for now pls don't bother to find some error i think i know where is the problem, if i don't succes i will comeback to tell.

    • Message #360

      Noop, still wrong, can you check please, for that error maybe you make changes lately..

  • Message #361

    My guess is that the jQuery plugin is not properly submitting the file upload. You can test this theory by changing the form to do a normal submit without jQuery and see if the same error occurs.

    • Message #362

      Ok, i will try this way,I know that javascript can handle file upload only with some flash or iframe in the back, but the form() plugin from jquery have this, i see it myself on two blogs. i will see whats happening with normal form subm.

      • Message #363

        so, yes was something wrong or with post jq plugin or wirh the form cretaed on the fly. i was trying to be a little to fancy.

        Now i have another problem.

        <form method="POST" id="form_new_record" action="actions.php?action=new" enctype="multipart/form-data">
        <label>Titlu:</label><br /><input name="titlu" type="text" mask="email" value="" class="text" /><br /><br />
        <label>Descriere:</label><br /><textarea name="descriere"  style="width:100%" id="descriere" class="text"></textarea><br />
        <label>Data:</label><br /><input name="data" type="text" class="datepicker" value="" /><br /><br />
        <label>Eticheta:</label><br /><input name="poza_1" type="file" value="" />
        <input name="new_record" type="submit" value="Introdu inregistrarea"  id="new_record" />
        </form>
        
        if (isset($_POST['new_record'])) {
         
            $poza = fRequest::get('poza_1');
            echo '--->'.$poza;
            
            $News = new News();
         
            try {
                $News->setActiv(1);
                $News->populate();
                $News->store();
                /*
                $uploader = new fUpload();
                $uploader->setMaxFileSize('2MB');
                $file = $uploader->move('../../_media/galerie/', 'poza_1');
                */
                                
            } catch (fExpectedException $e) {
                echo $e->getMessage();    
            }        
        }
        

        file upload works fine, but the 'poza_1' don't send the value, for insert into database. what i do wrong?

        • Message #364

          What is fRequest::get('poza_1'); returning in this case? If it is returning a value, then the fActiveRecord won't see it as a file upload. File uploads always come in through the $_FILES superglobal.