Skip to main content

Posts

Showing posts from November, 2010

php loop images in a folder, display them

This code will loop all the images inside "images" folder and display them. For every 7 images, a new row is added. <table> <tr> <?php $photo_dir = "images"; $files = glob($photo_dir."/*.*"); for ($i=0; $i<count($files); $i++) { $j = $i+1; ?> <td height="25" align="center"> <?php $num = $files[$i]; $img_name = explode(".", basename($num)); echo '<a href="'.$num.'"> <img src="'.$num.'" width="120" height="120" style="border:4px solid #FFF;"></a>'; // .$img_name[0]; ?> </td> <?php if($j % 7 == 0) echo '</tr><tr>'; } ?> </tr> </table>

Jquery css hacks

An example to control the style in various browsers: $(document).ready(function(){ if($.browser.msie) {    // IE $("#box").css({ "background": "none", "margin-top": "60px" }); }; if($.browser.mozilla) {   // Firefox $("#box").css({ "margin-top": "40px", "margin-left": "30px" }); }; if($.browser.safari) {    // Chrome $("#box").css({ "margin-top": "100px", "margin-left": "30px" }); }; });

php get ip address

<?php function getIpAddress() { return (empty($_SERVER['HTTP_CLIENT_IP'])?(empty($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['REMOTE_ADDR']: $_SERVER['HTTP_X_FORWARDED_FOR']):$_SERVER['HTTP_CLIENT_IP']); } echo getIpAddress(); ?>

check file type in upload

Script code: <script type="text/javascript">function check_upload(upload_field){    var re_text = /\.txt|\.pdf|\.zip/i;    var filename = upload_field.value; /* Checking file type */    if (filename.search(re_text) == -1)    {        alert("File does not have (txt / pdf / zip) extension");        upload_field.form.reset();        return false;    }return true; } function verify_upload(){ if(document.upload_file.file1.value == "") { alert("Please select a file"); return false; }return true; }</script> Form code: <form name="upload_file" action="" method="post" enctype="multipart/form-data"><input type="file" name="file1" id="file" onChange="check_upload(this)"><input type="submit" name="submit" value="Upload" onclick="return verify_upload()" /></form>

Disable right click on a page

<script language="javascript" type="text/javascript"> var message=""; function clickIE() {if (document.all) {(message);return false;}} function clickNS(e) { if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(message);return false;}}} if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.  onmousedown=clickNS;} else {document.onmouseup=clickNS;document.oncontextmenu  =clickIE;} document.oncontextmenu=new Function("return false") </script>