Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. You can try a force download of the file.

     

    <?php
    ob_start();
    
    $file = $_GET['file'];
    
    if(file_exists($file)){
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    }else {
    echo "File does not exist";
    }
    
    ob_end_flush();
    ?>

  2. <script language="Javascript">
    function chex(id){
    var val = document.getElementById(id).value;
    var newval = val.replace(/,/g,'');
    var finished = newval.replace(/\$/gi,'');
    
    document.getElementById(id).value = finished;
    }
    </script>
    
    <form method="get" onSubmit="chex('txt');chex('txt2')">
    <input type="text" name="txt" id="txt"><br>
    <input type="text" name="txt2" id="txt2">
    <input type="submit"></form>

     

    tested and worked fine.

  3. No, you could do something like this.

     

    <?php
    function color($c,$txt){ return "<font color=\"".$c."\">".$txt."</font>";  }
    
    $sql = "SELECT * FROM `users` ORDER BY username ASC";
    $res = mysql_query($sql) or die(mysql_error());
    
    $x = 0;
    while($row = mysql_fetch_assoc($res)){
    if($x % 2){
    	echo color('red',$row['username']) . " ";
    }else {
    	echo color('blue',$row['username']) . " ";
    }
    
    $x++;
    }
    ?>

  4. I'm not so good at regex, but you could just use str replace

     

    <?php
    $string = "onetwothreefourfive";
    
    $array = array("one","two","three","four","five");
    function color($c,$txt){ return "<font color=\"".$c."\">".$txt."</font>";  }
    $repl = array(color('blue','one'),color('red','two'),color('blue','three'),color('red','four'),color('blue','five'));
    
    echo str_replace($array,$repl,$string);
    ?>

  5. You're probably better off just defining individual variables.

     

    $cost1 = $_POST['cost1'];
    $cost2 = $_POST['cost2'];
    $cost3 = $_POST['cost3'];
    

     

    Or something like

     

    $cost[] = $_POST['cost' . $i]; // inside your while statement
    echo array_sum($cost); // after your while statement
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.