Welcome Guest, Not a member yet? Register   Sign In
  uploading and preview image with ajax
Posted by: El Forum - 05-29-2008, 10:02 AM - Replies (3)

[eluser]nuttynibbles[/eluser]
hello, im doing a function to upload photo. i would like to use ajax for user to preview the photo before submitting the form. so basically i want the user to click onto preview button where it will use ajax to preview the img to the user by saving the img file in a temp folder.

here is my code for the html:

Code:
<form name="frmregister" method="post" action="http://url/codeigniter/upload/do_upload" enctype="multipart/form-data">
<input type="hidden" name="post" value="1" />        
Upload a photo: <input type="file" name="file" id="file" /><input type="submit"  name="preview" value="preview">
<input class="button" type="submit" name="upload" value="upload" />
</form>

i found a ajax file on CI forum. it looks like this:
Code:
var ajaxPost = function() {
    
    // Get request object
    function getRequest() {
        if (window.XMLHttpRequest)
            return new XMLHttpRequest();
        else if (window.ActiveXObject)
            return new ActiveXObject("Microsoft.XMLHTTP");
        else
            alert('Ajax not supported');
        return null;
    }

    // Basic callback - could add error handler if you wanted
    function handleChange(req, callback) {
        if(req.readyState == 4) {
            if (req.status == 200) {
                if (callback)
                    callback(req.responseText);
            }
            else {
                alert("Ajax request failed.");
            }
        }
    }

    // Create query string from json object
    function handleParams(params) {
        if(!params) {
            return null;
        }
        else {
            var encoded = "";
            for (var field in params) {
                fieldval = params[field];
                encoded += field + '=' + fieldval + '&';
            }
            return encoded;
        }
    }

    // Combine it all in one pretty interface
    return function(uri, callback, data) {
        var request = getRequest();
        request.open('POST', uri, true);
        request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        request.onreadystatechange = function() { handleChange(request, callback) };
        request.send(handleParams(data));
        return request;
    };
}();

can someone show me how to go about doing this. tks


  turn off global xss on login page
Posted by: El Forum - 05-29-2008, 09:31 AM - Replies (4)

[eluser]Unknown[/eluser]
Okay, so this is what the problem is... I have global xss turned on so it sanitizes _post and what not.

However, I have a lot of users who use special characters in their password for security requirements so CI is converting them and making the password invalid.

How can I leave the global xss on but not sanitize the login page _post vars with its xss_clean function?

I thinking I need to do some kind of hook to turn it off specifically for that controller but just wanted to see what you guys thought.

Thanks


  Solved
Posted by: El Forum - 05-29-2008, 06:35 AM - Replies (2)

[eluser]JasonS[/eluser]
Solved


  help with a custom field_data()
Posted by: El Forum - 05-29-2008, 05:05 AM - Replies (4)

[eluser]dexter21[/eluser]
hi , iam trying to get all fields names and values from a table . i've made a custom query that return an array of elements.if i print $campo->valor, and $campo->nombre i obtain the results but if i call to function in a view it said that campo->nombre and campo->valor dont exisxt;

basicly i use following function as:

Code:
$sql = "select * from news";
$sql  .= " where nCodnoticia = 1";
registro=$this->db->query2($sql,$this->tabla);



$registro->campos[0]->type ->ok it print it
$registro->campos[0]->valor ->it give me an error, dont exist


any could help me plz ?


following function:

Code:
function query2($sql,$tabla)
    {

        $query = $this->query($sql);


        if ($query->num_rows() > 0)
        {
            $objeto = null;
            $objeto->campos = $query->field_data();

            $valores = $query->row();
            
            foreach($objeto->campos as $campo)
            {    
            
               echo $campo->name."<br>";
               echo $campo->type."<br>";
               echo $campo->max_length."<br>";
               echo $campo->primary_key."<br>";
                              

                foreach($valores as $nombre=>$valor)
                {
                    if($nombre == $campo->name)
                    {    
                    
                           $campo->valor = $valor;
                           $campo->nombre = $this->traduceCampo($tabla,$campo->name);


                            echo "campo->valor:".$campo->valor."<br>";
                            echo "campo->nombre:".$campo->nombre."<br>";
                                                
                           break;  
                     }
                 }
                
           }
        }
        else
        {
            $objeto = null;
            $objeto->campos = $query->field_data();
            foreach($objeto->campos as $campo)
            {
                   $campo->valor = null;
                   $campo->nombre = $campo->name;
            }
        }
        //echo var_dump($objeto);      
       return $objeto;
    }


  Multiple Databases Best Practice
Posted by: El Forum - 05-29-2008, 04:55 AM - Replies (4)

[eluser]matthewr[/eluser]
Hi! What's the best practice for connecting to multiple databases and using Active Record to access them both. I'll have 1 primary database that my app will access a lot, and one secondary database that my app will check out probably only during logins. I need two databases because the second database will be accessed by multiple apps. Could someone show me the best practice for doing this? I just want to do it right.

Thanks
Matthew


  2 or 3 fields of search
Posted by: El Forum - 05-29-2008, 04:16 AM - Replies (1)

[eluser]JUANITO26[/eluser]
Very Very Very good and impressive widget !
It is possible to activate 2 or 3 fields of search? (Quick Search)
Example ISO+NAME+NUMBER CODE.
If it is not much to ask, the form to do it
Thanks!


  .htaccess problem
Posted by: El Forum - 05-29-2008, 04:08 AM - Replies (5)

[eluser]Mitja[/eluser]

Code:
RewriteEngine on
RewriteRule ^$ /index.php [L]
RewriteCond $1 !^(index\.php|img|css|js|video_files|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]

i still need to write index.php in url adress. It is not recognized automatically. Anyone know why?


  XML-RPC Empty Return Structs
Posted by: El Forum - 05-29-2008, 04:07 AM - No Replies

[eluser]Elliot Haughin[/eluser]
Under 1.6.2, when using the XML-RPC Client library, an error occurs when handling 'empty' struct's.

libraries/Xmlrpc.php Line 1326:

Code:
switch($this->xmlrpcTypes[$typ])
{

    case 3:

        // struct

        $rs .= "<struct>\n";

        reset($val);

        while(list($key2, $val2) = each($val))

        {

            $rs .= "<member>\n<name>{$key2}</name>\n";

            $rs .= $this->serializeval($val2);

            $rs .= "</member>\n";

        }

        $rs .= '</struct>';

    break;

Produces:

Quote:A PHP Error was encountered

Severity: Warning

Message: reset() [function.reset]: Passed variable is not an array or object

Filename: libraries/Xmlrpc.php

Line Number: 1331
A PHP Error was encountered

Severity: Warning

Message: Variable passed to each() is not an array or object

Filename: libraries/Xmlrpc.php

Line Number: 1332


The library doesn't take into account that the struct could be empty...
should be:

Code:
switch($this->xmlrpcTypes[$typ])
{

    case 3:

        // struct

        $rs .= "<struct>\n";
        
        if ( !empty($val) )
        {

            reset($val);

            while(list($key2, $val2) = each($val))

            {

                $rs .= "<member>\n<name>{$key2}</name>\n";

                $rs .= $this->serializeval($val2);

                $rs .= "</member>\n";

            }
        }

        $rs .= '</struct>';

    break;

Maybe this isn't a bug... but just thought you might want to check it out.


  form_dropdown() always returns 0
Posted by: El Forum - 05-29-2008, 02:57 AM - Replies (6)

[eluser]EthanSP[/eluser]
Why is it that this form_dropdown() always returns 0?

form_dropdown($fby,$fy_values,$fy_default) // in view

where,

$fby is $data['fby'] = array('name'=>'birth_year'); // in model

$fy_values is $data['fy_values'] = $datelib->show_years(); // in model

function show_years() {
for ($x=date('Y')-150; $x<=date('Y'); $x++)
$years[] = $x;
return $years;
}

$fy_default is $data['fy_default'] = array_search(date('Y'),$data['fy_values']); // in model

In the controller:

if($this->input->post('mysubmit')) {
$this->mdl_demographics->save();
}

In the model:

$db_array = array('last_name' => $this->input->post('birth_year'));

Result in db:

last_name = 0

Why?


  Active Record Postgres stored procedure not working with 1 parameter
Posted by: El Forum - 05-29-2008, 02:19 AM - No Replies

[eluser]redguy[/eluser]
I have several plpgsql stored procedures in my database:
1) add_hit (integer, integer, integer)
2) add_score (integer, integer)
3) add_start (integer)

I call function 1 successfully with:

Code:
$result = $this->db->get("add_hit($sid,$qid,$aid)")->row_array();
The following SQL is generated:
Code:
SELECT * FROM add_hit(1,4,11)

I call function 2 successfully with:
Code:
$result = $this->db->get("add_score($sid,$qid)")->row_array();
The following SQL is generated:
Code:
SELECT * FROM add_score(1,34)

But when I call function 3 like that:
Code:
$result = $this->db->get("add_start($sid)")->row_array();
The following SQL is generated:
Code:
SELECT * FROM add_start("1")


It seems that CI adds quotes around the parameter. And while PHP allows a String to become an integer, Postgres doesn't. So I get an error. I solved this by running a manual query like:
Code:
$sql = "SELECT * FROM add_start($sid)";
$result = $this->db->query($sql)->row_array();
Which does the job.

I can't use the call_function function with Postgres, so I'm wondering if this is an AR bug?


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Error / Shield 1.0.3 + Ci...
by kenjis
30 minutes ago
Integrating Bootstrap 5 i...
by tarcisiodev1
1 hour ago
Asset Minification Packag...
by tarcisiodev1
1 hour ago
Modify users data as an a...
by luckmoshy
2 hours ago
Is it possible to go back...
by ejimenezo
7 hours ago
SQL server connection not...
by davis.lasis
11 hours ago
Validation | trim causes ...
by Gary
Today, 05:09 AM
Problem with session hand...
by Julesb
Today, 04:13 AM
External script access to...
by PomaryLinea
Today, 03:58 AM
VIRUS reported after Chro...
by InsiteFX
Yesterday, 11:34 PM

Forum Statistics
» Members: 85,495
» Latest member: qh88lode
» Forum threads: 77,586
» Forum posts: 376,025

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB