print div content November 7, 2009
Posted by ashwinisingh in Java Script.Tags: print div content
add a comment
<script type=”text/javascript”>
<!–
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open(”,’printwin’,’left=100,top=100,width=400,height=400,visible=false’)
newwin.document.write(‘<HTML>\n<HEAD>\n’)
newwin.document.write(‘<TITLE>Print Page</TITLE>\n’)
newwin.document.write(‘<script>\n’)
newwin.document.write(‘function chkstate(){\n’)
newwin.document.write(‘if(document.readyState==”complete”){\n’)
newwin.document.write(‘window.close();\n’)
newwin.document.write(‘}\n’)
newwin.document.write(‘else{\n’)
newwin.document.write(‘setTimeout(“chkstate()”,2000)\n’)
newwin.document.write(‘}\n’)
newwin.document.write(‘}\n’)
newwin.document.write(‘function print_win(){\n’)
newwin.document.write(‘window.print();\n’)
newwin.document.write(‘chkstate();\n’)
newwin.document.write(‘}\n’)
newwin.document.write(‘<\/script>\n’)
newwin.document.write(‘</HEAD>\n’)
newwin.document.write(‘<BODY onload=”print_win()”>\n ‘)
newwin.document.write(str)
newwin.document.write(‘</BODY>\n’)
newwin.document.write(‘</HTML>\n’)
newwin.document.close()
}
//–>
</script>
<div style=”margin-top: 20px;” id=”directions”></div>
<a href=”#null” onclick=”printContent(‘directions’)”>Click to print </a>
fined ip address November 7, 2009
Posted by ashwinisingh in PHP.Tags: fined ip address
1 comment so far
<?php
include(“finedip.php”); // Must include this
// ip must be of the form “192.168.1.100”
// you may load this from a database
$ip = $_SERVER[“REMOTE_ADDR”];
echo “Your IP Address is: ” . $ip . “<br />”;
echo “Your Country is: “;
// returns country code by default
echo getCountryFromIP($ip);
echo “<br />\n”;
// optionally, you can specify the return type
// type can be “code” (default), “abbr”, “name”
echo “Your Country Code is: “;
echo getCountryFromIP($ip, “code”);
echo “<br />\n”;
// print country abbreviation – case insensitive
echo “Your Country Abbreviation is: “;
echo getCountryFromIP($ip, “AbBr”);
echo “<br />\n”;
// full name of country – spaces are trimmed
echo “Your Country Name is: “;
echo getCountryFromIP($ip, ” NamE “);
echo “<br />\n”;
echo $_SERVER[‘REMOTE_ADDR’] ;
?>
Before use plz rename finedip.doc to finedip.php
ftp connection code November 7, 2009
Posted by ashwinisingh in PHP.Tags: ftp connection code
1 comment so far
<?php
$ftp_server = “www.yoursite.com”;
$ftp_user_name = “username”;
$ftp_user_pass = “password”;
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) || (!$login_result)) {
echo “FTP connection has failed!”;
echo “Attempted to connect to $ftp_server for user $ftp_user_name”;
exit;
} else {
echo “Connected to $ftp_server, for user $ftp_user_name”;
}
$dir = “”;
function filecollect($dir,$filelist) {
global $conn_id; //Get our ftp
$files = ftp_nlist($conn_id,$dir); //get files in directory
foreach ($files as $file) {
//$isfile = ftp_size($conn_id, $file);
if($isfile == “-1”) { //Is a file or directory?
$filelist = filecollect($dir.’/’.$file,$filelist,$num); //If a folder, do a filecollect on it
}
else {
$filelist[(count($filelist)+1)] = $file; //If not, add it as a file to the file list
}
}
return $filelist;
}
$filelist = filecollect($dir,$filelist);
echo “<pre>”;
print_r($filelist);
echo “</pre>”;
$dir=”yoursite.com”;
$filelist = filecollect($dir,$filelist);
echo “<pre>”;
print_r($filelist);
echo “</pre>”;
$new=explode(“/”,$filelist[’73’]);
$myFile =$new[1];
//echo “$myFile”;
$fh = fopen($myFile, ‘r’) or die(“can’t open file”);
//$fh = fopen($myFile, ‘w’) or die(“can’t open file”);
//$stringData = “Ashwani\n”;
//fwrite($fh, $stringData);
$the = fread($fh, 1000000);
fclose($fh);
?>
<form action=”” method=”post” enctype=”multipart/form-data” name=”form”><table width=”100%” border=”0″>
<tr>
<td><? echo $new[1]; ?></td>
<td><textarea name=”textarea” cols=”40″ rows=”40″><? echo $the; ?></textarea></td>
</tr>
</table>
</form>
Import excel file into mysql data base November 7, 2009
Posted by ashwinisingh in PHP.Tags: Import excel file into mysql data base
add a comment
<?
i$db = mysql_connect(“localhost”, “root”, “”) or die(“Could not connect.”);
if(!$db)
die(“no db”);
if(!mysql_select_db(“test”,$db))
die(“No database selected.”);
if(isset($_POST[‘submit’]))
{
$filename=$_POST[‘filename’];
$handle = fopen(“$filename”, “r”);
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE)
{
$import=”INSERT into sample(name,email) values(‘$data[0]’,’$data[1]’)”;
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print “Import done”;
}
else
{
print “<form action=’import.php’ method=’post’>”;
print “Type file name to import:<br>”;
print “<input type=’text’ name=’filename’ size=’20’><br>”;
print “<input type=’submit’ name=’submit’ value=’submit’></form>”;
}
?>
Page location tracker November 7, 2009
Posted by ashwinisingh in PHP.Tags: Page location tracker
add a comment
<?
$domain = $_SERVER[‘HTTP_HOST’];
// find out the path to the current file:
$path = $_SERVER[‘SCRIPT_NAME’];
// find out the QueryString:
$queryString = $_SERVER[‘QUERY_STRING’];
// put it all together:
$pieces = explode(“/”, $path);
$count=count($pieces);
for($i=0;$i<= $count;$i++)
{
if($pieces[$i]==”courses.php”)
{
unset($pieces[$i]);
break;
}
}
$newurl = implode(“/”, $pieces);
?>
<form method=”post” action=<? echo “https://” . $domain . $newurl .”/test.php” ?> name=”frm”>