PHP Code : $fp = fopen('filename.CSV','r') or die("can't open file"); print "<table>\n"; while($csv_line = fgetcsv($fp,1024)) { print '<tr>'; for ($i = 0, $j = count($csv_line); $i < $j; $i++) { print '<td>'.$csv_line[$i].'</td>'; } print "</tr>\n"; } print '</table>\n'; fclose($fp) or die("can't close file");
Wednesday, March 14, 2012
Reading File content From CSV File Using PHP Script
File Download using PHP Script
0){
$seek_start = intval($range[0]);
}
if($range[1] > 0){
$seek_end = intval($range[1]);
}
// Seek to the requested position in the file
fseek($fp, $seek_start);
// Set the range response headers
header(‘HTTP/1.1 206 Partial Content’);
header(‘Content-Length: ‘ . ($seek_end – $seek_start + 1));
header(sprintf(‘Content-Range: bytes %d-%d/%d’, $seek_start, $seek_end, $size));
}
else
{
// Set default response headers
header(‘Content-Length: ‘ . $size);
}
// Set up the size of each piece of data we send
$block_size = 1024;
if($rate > 0)
{
// Multiply by rate if specified
$block_size *= $rate;
}
// Prevent the script from timing out
set_time_limit(0);
// Start sending the file
while(!feof($fp))
{
// Output data
print(fread($fp, $block_size));
flush();
if($rate > 0)
{
// Wait one second before next block if rate is specified
sleep(1);
}
}
// Close the file
fclose($fp);
}
?>
Capcha code integration with php
Paste the code in php page and download the monofont.ttf font and paste in the same folder.
Php Code:
var $font = ‘./monofont.ttf’;
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = ’23456789bcdfghjkmnpqrstvwxyz’;
$code = ”;
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function Captcha($width=’120′,$height=’40′,$characters=’6′) {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = imagecreate($width, $height) or die(‘Cannot initialize new GD image stream’);
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die(‘Error in imagettfbbox function’);
$x = ($width – $textbox[4])/2;
$y = ($height – $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die(‘Error in imagettftext function’);
/* output captcha image to browser */
header(‘Content-Type: image/jpeg’);
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) && $_GET['width'] < 600 ? $_GET['width'] : ’100′;
$height = isset($_GET['height']) && $_GET['height'] < 200 ? $_GET['height'] : ’30′;
$characters = isset($_GET['characters']) && $_GET['characters'] > 2 ? $_GET['characters'] : ’6′;
$captcha = new Captcha($width,$height,$characters);
?>
Disabling right click in Javascript
<script language=”JavaScript”>
var message=”Right Click Disabled”;
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>