Forums

File Upload and link it in Database

d3x73r 05 Oct, 2010
Hi again...
I'm working on another module now where I need to upload a file, update some info on a table, refering to the user that uploaded it.
I've being trying but no success until now. Here is my codes:

<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>

<div class="form_item">
    <h1>Envio do Comprovante</h1>
</div>

<div class="form_item">
  <span class="cf_text">Envie aqui o comprovante de pagamento.</span>
</div>

<div class="form_item">
    <label>Enviar Boleto</label><br />
    <input class="cf_fileinput cf_inputbox required" title="Você deve selecionar um arquivo." size="20" id="file_0" name="file_0" type="file" />
    <a class="tooltiplink" onclick="return false;"><img height="15" border="0" width="15" class="tooltipimg" alt="" src="images/site/tooltip.png"/></a>
                <div class="tooltipdiv">Boleto :: Envie o arquivo do boleto.</div>
  <div class="cfclear"> </div>
</div>
<div class="form_item">
    <input value="Enviar" name="button_15" type="submit" /><input type="reset" name="reset" value="Reset"/>
  <div class="cfclear"> </div>
</div>

On submit code before:

<?php
    $user =& JFactory::getUser();
    $db =& JFactory::getDBO();
    $query = "
        SELECT `cf_id`
            FROM `#__chronoforms_usuarios`
            WHERE `cf_user_id` = '".$user->id."' ;
    ";
    $db->setQuery($query);
    $cf_id = $db->loadResult();
    JRequest::setVar('cf_id', $cf_id);
?>


Auto generated:

<?php
        $MyForm =& CFChronoForm::getInstance("comprovante");
        if($MyForm->formparams("dbconnection") == "Yes"){
            $user = JFactory::getUser();            
            $row =& JTable::getInstance("chronoforms_usuarios", "Table");
            srand((double)microtime()*10000);
            $inum    =    "I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
            JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
            JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
            JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
            JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
            $post = JRequest::get( "post" , JREQUEST_ALLOWRAW );            
            if (!$row->bind( $post )) {
                JError::raiseWarning(100, $row->getError());
            }                
            if (!$row->store()) {
                JError::raiseWarning(100, $row->getError());
            }
            $MyForm->tablerow["jouefs10_chronoforms_usuarios"] = $row;
        }
        ?>


I need help to make it work, please!
GreyHead 06 Oct, 2010
Hi d3x73r,

Which part isn't working?

Please turn debug on in the form General Tab, then submit the form and post the debug - including any 'dummy emails' results here.

Is the DB Connection set to 'After Email'?

Bob
d3x73r 06 Oct, 2010
Sorry for don't post the debug before.
I tested now and the e-mail is working, but the database isn't registering nothing.

Here is the e-mail it's sending:

From: JOUEFS [from-email]
To: my-email
CC:
BCC:
Subject: Boleto JOUEFS
Envio do Comprovante
Envie aqui o comprovante de pagamento.

3 {nome}
Enviar Boleto
20101006133009_IMAGE_00061.jpg
Boleto :: Envie o arquivo do boleto.


Submitted by 10.65.16.2

Files: D:\inetpub\wwwroot\jouefs\2010\components\com_chronocontact\uploads\comprovante\20101006133009_IMAGE_00061.jpg

Check that it isn't getting a field {nome}. {nome} is a field on the database.

Here is the debug

   1. Form passed first SPAM check OK
   2. Form passed the submissions limit (if enabled) OK
   3. Form passed the Image verification (if enabled) OK
   4. Form passed the server side validation (if enabled) OK
   5. $_POST Array: Array ( [button_15] => Enviar [4542a1e7d7425e35099abe97228a62d2] => 1 [1cf1] => 014393e210dba4cc39636d880b5b0733 [chronoformname] => comprovante )
   6. $_FILES Array: Array ( [file_0] => Array ( [name] => IMAGE_00061.jpg [type] => image/jpeg [tmp_name] => C:\Windows\php193A.tmp [error] => 0 [size] => 340796 ) )
   7. Upload routine started for file upload by : file_0
   8. D:\inetpub\wwwroot\jouefs\2010\components\com_chronocontact\uploads\comprovante\20101006133009_IMAGE_00061.jpg has been uploaded OK
   9. Form passed the plugins step (if enabled) OK
  10. An email has been SENT successfully from (JOUEFS)from-email to to-email
  11. Debug End


The Saving Data is set to after e-mail.

Thanks!
d3x73r 06 Oct, 2010
Nevermind... I got it working now.
It was some mistake with field names on my html form.

Thanks!
d3x73r 06 Oct, 2010
Me again...🙂
Is that any way to put a link for this file in a form?
GreyHead 06 Oct, 2010
Hi d3x73r,

Yes. You look up the file name in the database and build a normal HTML link to it.

Bob
This topic is locked and no more replies can be posted.