Jump to content

joymis

Members
  • Posts

    37
  • Joined

  • Last visited

Posts posted by joymis

  1. Hello,

    I have this code

    <button class="btn btn-info" onclick="BatchAsign()">Batch</button>
    
    <button class="asign_btn" onclick="Asign({a:'1', b:'2'}, this)">Asign1</button>
    <button class="asign_btn" onclick="Asign({a:'2', b:'6'}, this)">Asign2</button>
    <button class="asign_btn" onclick="Asign({a:'5', b:'4'}, this)">Asign3</button>
    
    <script>
    function BatchAsign(){
    	$.each( $('.asign_btn'), function( key, val ) {
    		$(this).trigger( "click", ['all'] )
    	});
    }
      
    function Asign(arr, dom, x)
    {
      if(x == 'all'){
        // I want do something
      }
    }
    </script>

    When I click BatchAsign button, I want pass a extra parameters to Asign.

    I used console.log(x), it's display 'undefined'.

    How can I get string 'all' in the function Asign?

    thanks.

  2. 8 hours ago, justsomeguy said:

    You would send the data for the first two and just save the data in the session instead of inserting or updating the database, and on the third request you get the rest of the data from the session and insert everything.

    Thanks for your reply. I will try this method.

  3. Hello,

    I have a web dirs like this

    /
    obj/
        a.php
        b.php
        c.php
    test/
        d.php

    Contents of these files:

    d.php:

    require_once '../obj/a.php';

    a.php:

    require_once 'b.php';

    b.php:

    require_once 'c.php';

    then I run d.php, the log display:

    PHP Warning:  require_once(c.php): failed to open stream: No such file or directory in /var/www/xxx/test/b.php
    PHP Fatal error:  require_once(): Failed opening required 'c.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/xxx/test/b.php

    Is there something obvious I'm missing? how do include paths work in PHP?

    thanks.

  4. On 2017/6/10 at 0:39 AM, justsomeguy said:

    If you don't know what the type will be, then use a length that will be long enough for anything.

    ok, thank you for your help

  5. 9 hours ago, justsomeguy said:

    You need to figure that out, because you have to set a length:

    but my OUT bind type maybe number or string or array, or have any function can get OUT bind length?

    class DBObj{
      public function spExec($sql, $params){
        $stid = oci_parse($this->con, $sql);
    
        foreach ($params as $key => &$value) 
        {
            if($value == 'sp_return')
                // I'm not sure $len
                // could I use something function get OUT bind length?
                oci_bind_by_name($stid, $key, $r, $len);
            else
                oci_bind_by_name($stid, $key, $value);
        }
    
        oci_execute($stid, OCI_DEFAULT) or die($this->dbError($stid));
    
        return $r;
      }
    }
    
    $db = new DBObj();
    
    // maybe this return number
    $sql = "BEGIN :ret := aaa(:p1, :p2, :p3); END;";
    $params = array(':ret' => 'sp_return', ':p1' => '1', ':p2' => '2', ':p3' => '3');
    $result = $db->spExec($sql, $params);
    echo $result;
    
    // maybe this return string or array
    $sql = "BEGIN :ret := bbb(); END;";
    $params = array(':ret' => 'sp_return');
    $result = $db->spExec($sql, $params);
    echo $result;

     

  6. Hello,

    I have some code like this

    $sql = "BEGIN :ret := sifw.sf_todoList('38000', '', 'all'); END;";
    
    $stid = oci_parse($conn, $sql);
    
    oci_bind_by_name($stid, ':ret', $r);
    
    oci_execute($stid);

    I got a error : 「ORA-06502: PL/SQL: numeric or value error: character string buffer too small」

    if I change oci_bind_by_name($stid, ':ret', $r) to oci_bind_by_name($stid, ':ret', $r, 200), it's work

    but I don't want to set a current length, because I do not know OUT bind type and length.

    how can I fixed this error?

    Thanks

  7. 17 hours ago, Ingolme said:

    An iframe is the only way. Why don't you want to use an iframe?

    because it's height and scrollbar always out of control and let me crazy.

    It looks like I will have no choice. :facepalm:

  8. 18 hours ago, dsonesuk said:

    With the code I provided, it does not require being placed in function, it runs its own anonymous function if a specific classed element within a specific parent id element is clicked even if a specific currently classed element already exists OR is newly created which is what 'on()' is specifically used for.

    Thank for your help, I'm not notice your main is $("#unexe_table").on("click", ".up, .down", function() {...}) not $(".up, .down").on("click", function() {...})

    $("#unexe_table").on("click", ".up, .down", function() {...}) can be work

    thanks.

  9. 21 hours ago, Ingolme said:

    Every time you create a new row you're adding another event handler to all the rows. The newest row will have just one event handler, but the older rows will have as many event handlers as times you've clicked the "new" button.

     

    19 hours ago, rockey91 said:

    Hi Joymis, as Ingolme said the event is being added every time the new row is added. Here is the fix - https://jsfiddle.net/rockey91/8zzq635c/

    Thank you for your help, I thought it would cover the original event handler

     

    11 hours ago, dsonesuk said:

    Events like these are applied to elements on loading of the page, if you place them in a function you apply the exactly the same event with same outcome again everytime the function is called, very inefficient, generally if these are placed in function you are doing it wrong.

    You don't even require the function, you just need to target the parent and then the newly created class references.

    my code was originally written like this, but tbody content from ajax return and I have use blockUI plugin

    function SearchQuery(){	
    	$.ajax({
    		......
    		async: false,
    		beforeSend:function(){
    			$.blockUI({ 
    				css: {
    					border: 'none',
    					padding: '15px',
    					backgroundColor: '#000',
    					'-webkit-border-radius': '10px',
    					'-moz-border-radius': '10px',
    					opacity: .5,
    					color: '#fff'
    				},
    				message: '<p>Searching,please wait...</p>' 
    			});
    		},
    		success: function(response) { 
    			$("#query_content_unexe").html(response['query_content']);
    
    			actOrder();
    		},
    		complete:function(){
    			$.unblockUI();
    		}
    	})
    }

    when I use "async: false" blockUI will not work,

    if I no use "async: false" up and down click will not work,

    so I used the function

  10. Hello,

    I have some html code like this

    <table>
      <thead>....</thead>
      <tbody id="content">
        <tr>
          <td>
          	<img ......>
            <img onclick="test()" src="1.jpg">
          </td>
        </tr>
        <tr>
          <td><img onclick="test()" src="3.jpg"></td>
        </tr>
        <tr>
          <td>
            <img ......>
            <img ......>
            <img onclick="test()" src="2.jpg">
          </td>
        </tr>
      </tbody>
    </table>

    when I onclick 3.jpg, I want get tr index is 1, and I onclick 1.jpg, I want get tr index is 0

    how can I use jQuery or javascript get the tr index and no use like parentNode api?

    because I not sure parentNode of img must be td, maybe it's div, span, or a table.

    Thanks.

  11. Hello,

     

    I have some environment variables...like

     

    upload_path = 'abc/'

    upload_size = '5M'

    sys_id = 'w3c'

    session_time = '600'

    ......

     

    I want use DB or use *.ini access these variables.

     

    whcih one is better and safe?

     

    Thanks.

  12. Hi all,

    I have a data like this,

     

    dept_no under_dept level

    01000 01000 0

    01010 01000 1

    03000 01000 1

    03010 03000 2

    03016 03010 3

    03020 03000 2

    03050 03000 2

    03056 03050 3

    91020 91020 1

     

    now I have a var $x = 01000, then I should get all data row,

     

    when $x = 03000, then I should get dept_no like '03%' row

     

    when $x = 03010, then I should only get dept_no = 03010 and 03016 row

     

    does anyone have good idea can tell me how can I do?

     

    thanks

  13. Hello,

     

    I have a javascript code like this

    <input type="file" class="filename" onchange="myFunction(this)">
    
    <script>
    function myFunction(elem) {
        if(elem.value.replace(/C:\\fakepath\\/g ,"").length > 20)
        {
    	elem.value = elem.defaultValue;
    	alert('The file name too long!');
    	return false;
        }
        else{
             alert('OK');
        }
    }
    </script>
    

    when I select a file, the IE11 will display two message, fisrt alert 'ok' then alert 'The file name too long!'

     

    but firefox and chrome is correct, only display 'The file name too long!'

     

    how can I do that IE11 only display one message?

     

    Thanks.

  14. Yeah, I'm not sure what you're doing there. You add an extra line break character to the end of the encrypted data when you write it to the file, and then for some reason when you read the encrypted file you get each line in an array, remove the last line break, and then try to individually decrypt each line. Why are you doing that? The data should all be encrypted and decrypted at once, not in segments. Line breaks do not mean anything in encrypted data, they are just another sequence of bits. Again, this is not text data you are dealing with, it is binary data. Don't look for particular sequences of bits in the encrypted data and treat them like characters like line breaks. It is just a continuous sequence of bits and you should treat the entire thing as one piece of data, not break it up into smaller pieces and then try to decrypt each one. That's why you're getting different sizes, because you are decrypting something totally different than what the data is.

    ok, thank you very much for your explanation, now I fully understand.

     

     

    $x = public_encrypt(file_get_contents('test.png'));

    file_put_contents('enc.png', $x);

    I tried file_get_contents() after the encrypt file still 0 byte, might it openssl_private_encrypt() has special rule?

     

    I looks php.net website, it said..

     

    openssl_private_encrypt() has a low limit for the length of the data it can encrypt due to the nature of the algorithm.

     

    To encrypt the larger data you can use openssl_encrypt() with a random password (like sha1(microtime(true))), and encrypt the password with openssl_public_encrypt().

     

    But my test file only had 24KB, is it a large data?

  15. Hello justsomeguy,

     

    I had think read the entire file at once and encrypt, but I don't know why not work, this is my entire file at once code

    $file = fopen('test.png', "rb");
    $fp = fopen('enc.png', 'w');
    
    $x = fread($file, filesize('test.png'));
    fwrite($fp, public_encrypt($x)); // I got 0 byte file
    // fwrite($fp, $x); ==> it's work
    
    fclose($file);
    fclose($fp);

    And in my original case, I tried more method like this, but after decrypted the file size not equal original file size.

    $file = fopen('test.png', "r");
    $fp = fopen('enc.png', 'w');
        
    while(! feof($file)){
        $x = public_encrypt(fgets($file));
        fwrite($fp, $x."\n");
    }
    fclose($file);
    fclose($fp);
        
        
    $file = fopen('enc.png', 'r');
    $fp = fopen('dec.png', 'w');
        
    while(! feof($file)){
        $z[] = fgets($file);
    }
    array_pop($z);
    foreach($z as $v)
    {
        $aaa = explode("\n", $v);
        $z = private_decrypt($aaa[0]);
        fwrite($fp, $z);
    }
    fclose($fp);
    fclose($file);

    In addition to RSA encryption, are there more better encryption tools or method can let me reference?

     

    Thanks.

  16. Hello,

     

    I have a RSA encrypt / decrypt function from google, and I try it for file upload

     

    this is my code

    <?php
    	const PRIVATE_KEY = 'private_2048.key';
    	const PUBLIC_KEY = 'public_2048.crt';
    
    	$file = fopen('test.jpg', "r");
    	$fp = fopen('enc.jpg', 'w');
    	
    	while(! feof($file)){
    		$x = public_encrypt(fgets($file));
    		var_dump($x);
    		
    		fwrite($fp, $x);
    	}
            /**  it's display this
                 string(344) "CZtRordK+BC/fUJX1P2FD8Yt0217bquw.......
                 string(344) "I9m8ZLRz1FACXVmWWlmzISS..........
                 string(0) ""
                 string(344) "dp5vPnpZhEpz6K4Cmh........
                 string(0) ""
                 string(344) "mT60XZEph87lOz.......
                 string(0) ""
                 string(0) ""
                 string(0) ""
    	*/
            fclose($file);
    	fclose($fp);
    	
    	
    	$file = fopen('enc.jpg', "r");
    	$fp = fopen('dec.jpg', 'w');
    	
    	while(! feof($file)){
    		$z = fgets($file);
    		var_dump($z);
    		
    		fwrite($fp, private_decrypt($z));
    	}
    	/** it's display this
                string(1376) "CZtRordK+BC/fUJX1P2FD8Yt02..........
            */
    	fclose($fp);
    	fclose($file);
    
    function public_encrypt($plaintext)
    {
        $fp = fopen(PUBLIC_KEY, "r");
        $pub_key = fread($fp, 8192);
        fclose($fp);
        
        $pub_key_res = openssl_get_publickey($pub_key);
        if(!$pub_key_res) {
            throw new Exception('Public Key invalid');
        }
        openssl_public_encrypt($plaintext,$crypttext, $pub_key_res);
        openssl_free_key($pub_key_res);
    	
        return(base64_encode($crypttext));
    }
    
    function private_decrypt($encryptedext)
    {
        $fp = fopen(PRIVATE_KEY, "r");
        $priv_key = fread($fp, 8192);
        fclose($fp);
    	
        $private_key_res = openssl_get_privatekey($priv_key);
        if(!$private_key_res) {
            throw new Exception('Private Key invalid');
        }
        openssl_private_decrypt(base64_decode($encryptedext), $decrypted, $private_key_res);
        openssl_free_key($private_key_res);
    	
        return $decrypted;
    }
    ?> 
    

    in my code, I var_dump $x and then if I decrypt and var_dump, it's work.

    but when I read encrypt file and var_dump $z, it's not the same $x.

    how can I do let $z = $x?

     

    Thanks.

×
×
  • Create New...