Welcome Guest, Not a member yet? Register   Sign In
Problems with Forms input files....
#1

[eluser]Paulodemoc[/eluser]
Hello all.... i program with codeigniter for some time now. I've already worked with files uploads, including image redimensioning and cropping. But now Im having some problems...

I made a view with a form with 3 fields: text for a title, textarea for description and file for uploading a pdf...

i've used this same for for another controller, and it worked just fine, i've just changed the field names and ids....

when i input some title and description, and select any file type, it works just fine, but the upload fails because the filetypes are not supported (it is suposed to fail, 'cause I want to upload PDFs only....)

But that's the problem... when i select a pdf (and it is suposed to work), the form_validation->run() was failing... when i checked why, i found this: everytime i select a pdf on the file input and click submit, the $_POST and $_FILES globas are going empty..... i don't know why... and wasn't able to find help... would anybody here know the reason?

bellow is the code from my controller and from my view...:

view:
Code:
<?php echo form_open_multipart("pdfs/pdf/$mode",array("id"  =>  "formInsertPdf")); ?>
  <fieldset>
    <legend>Título</legend>
    <label>
      &lt;input type="text" id="titulo" name="titulo" size="40" value="&lt;?php echo set_value('titulo'); ?&gt;"&gt;
      <font size="1"><br>
      &lt;?php echo "<font color='red'>".strip_tags(utf8_encode(form_error('titulo')))."</font>"; ?&gt;</font></label>
  </fieldset>
  <fieldset>
    <legend>Descrição</legend>
    <label>
      &lt;textarea id="descricao" name="descricao" cols="50" rows="10"&gt;&lt;?php echo set_value('descricao'); ?&gt;&lt;/textarea&gt;
      <font size="1"><br>
      &lt;?php echo "<font color='red'>".strip_tags(utf8_encode(form_error('descricao')))."</font>"; ?&gt;</font></label>
  </fieldset>
  <fieldset>
    <legend>Arquivo</legend>
    <label>
      &lt;input type="file" id="arquivo" name="arquivo" label="Arquivo" size="40"/&gt;
      <br>
      <font size="1">
      &lt;?php if(isset($file_error)) echo "<font color='red'>".strip_tags($file_error)."</font>"; else echo "<font color='red'>".strip_tags(form_error('arquivo'))."</font>"; ?&gt;
      </font></label>
  </fieldset>
  <fieldset>
    <center>
      &lt;input type="submit" id="submit" name="submit" value="Enviar"&gt;
    </center>
  </fieldset>
  &lt;/form&gt;

and the controller
...
Code:
function pdf($mode, $id = '') {
$data['mode']        =        $mode;
$data['pdf']        =        $this->Pdf_model->getPdf($id);

//I DID THIS TO CHECK IF THE POST AND FILES WAS GETTING ANY VALUES
//print_r($_FILES); echo '<br/>'; print_r($_POST); die;

if ($this->form_validation->run() == FALSE) {
  $this->load->view('admin/pdf', $data);
}
else {
  if($mode == 'insert')
  {
   $pdf['titulo']        =        $_POST['titulo'];
   $pdf['descricao']    =        $_POST['descricao'];
   $this->folder                 =       'uploads/pdfs/';
   if (!is_dir($this->folder)) mkdir($this->folder,0777);
   $pdf['status']        =        true;
   $file_pdf            =        $this->_uploadFile('arquivo','pdf');
   if (!is_array($file_pdf)) {
    $data['file_error']       =           $file_pdf;
    $data['msg']              =           'Ocorreu um erro ao enviar o PDF!';
    $this->load->view('admin/pdf',$data);
   }
   else {
    $pdf['arquivo']             =          $file_pdf['file'];
    $pdf['arquivo_url']         =          $file_pdf['fileURL'];
    $pdf['index']        =        $this->Pdf_model->getPdfsQt() + 1;
    if($this->Pdf_model->insertPdf($pdf))
    {
    $data['msg']              =           'PDF adicionado com sucesso!';
    redirect('pdfs/listar', 'refresh');
    }
   else {
    $data['msg']              =           'Ocorreu um erro ao enviar o PDF!';
    $this->load->view('admin/pdf',$data);
    }
  }
}
elseif($mode == 'update')
{
$pdf                        =        $this->Pdf_model->getPdf($id);
$newPdf['idPdf']            =        $id;
$newPdf['titulo']            =        $_POST['titulo'];
$newPdf['descricao']        =        $_POST['descricao'];
$newPdf['status']            =        true;
if($_FILES['arquivo']['name'] != '')
{
$this->folder             =       'uploads/pdfs/';
if (!is_dir($this->folder)) mkdir($this->folder,0777);
$file_pdf                =        $this->_uploadFile('arquivo','pdf');
if (!is_array($file_pdf)) {
$data['file_error']           =           $file_pdf;
$data['msg']              =           'Ocorreu um erro ao atualizar o PDF!';
$this->load->view('admin/pdf', $data);    
}
else {
$newPdf['arquivo']          =          $file_pdf['file'];
$newPdf['arquivo_url']      =          $file_pdf['fileURL'];
unlink('uploads/pdfs/'.$pdf->arquivo);
}
}
else
{
$newPdf['arquivo']              =          $pdf->arquivo;
$newPdf['arquivo_url']          =          $pdf->arquivo_url;
$newPdf['index']                    =        $pdf->index;
if($this->Pdf_model->updatePdf($newPdf))
{
$data['msg']              =           'PDF atualizado com sucesso!';
redirect('pdfs/listar', 'refresh');
}
else
{
$data['msg']              =           'Ocorreu um erro ao atualizar o PDF!';
$this->load->view('admin/pdf', $data);                    
}
}
}
}
...


I would appreciate any help...

Thanks in advance.


Messages In This Thread
Problems with Forms input files.... - by El Forum - 05-26-2009, 06:34 AM
Problems with Forms input files.... - by El Forum - 05-26-2009, 07:28 AM
Problems with Forms input files.... - by El Forum - 05-26-2009, 07:38 AM
Problems with Forms input files.... - by El Forum - 05-26-2009, 07:41 AM
Problems with Forms input files.... - by El Forum - 05-26-2009, 07:42 AM
Problems with Forms input files.... - by El Forum - 05-26-2009, 07:44 AM
Problems with Forms input files.... - by El Forum - 05-26-2009, 07:45 AM
Problems with Forms input files.... - by El Forum - 05-26-2009, 08:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB