Flipkart
Wednesday, April 14, 2010
Write PHP Code in HTML File
In two ways we can achieve this.
1.change the setting in apache configuration file(i.e httpd.conf)
AddType application/x-httpd-php .php ---> AddType application/x-httpd-php .php .html
2. If you don't have the access to httpd.conf you can write .htacees file as
AddType application/x-httpd-php .php .htm .html
and then restart the apache webserver.
Tuesday, April 13, 2010
prototype.js / jQuery.js conflict and resolution
when you use jQuery and prototype javascript frameworks togather on the same page, it creates conflicts.
jQuery has provided a resolution to this conflict. The resolution goes as below:
verriding the $-function:
1) you can override that default by calling jQuery.noConflict() at any point after jQuery and the other library have both loaded. For example:
<script src="prototype.js">
</script>
<script src="jquery.js">
</script>
<script>
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
</script>
2) Additionally, there's another option. If you want to make sure that
jQuery won't conflict with another library - but you want the benefit
of a short name, you could do something like this:
<script src="prototype.js">
</script>
<script src="jquery.js">
</script>
<script>
var $j = jQuery.noConflict();
// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});
// Use Prototype with $(...), etc.
$('someid').hide();
</script>
Thursday, April 8, 2010
PHP : Convert PDF Image file to JPEG Using Image magick
< ?php
define('THUMB_WIDTH', 150);
define('THUMB_HEIGHT', 212);
function makeThumbnail($in, $out) {
$width = THUMB_WIDTH;
$height = THUMB_HEIGHT;
$identify = shell_exec("identify -verbose ".$in);
$matches = array();
$pattern = '/Geometry: ([0-9]{1,})x([0-9]{1,})/';
$result = preg_match($pattern, $identify, $matches);
if( $result && count($matches) ) {
$h = $matches[1];
$w = $matches[2];
}
$thumbRatio = $width/$height;
$inRatio = $w/$h;
$isLandscape = $inRatio > $thumbRatio;
$size = ($isLandscape ? '1000x'.$height : $width.'x1000');
$xoff = ($isLandscape ? floor((($inRatio*$height)-$width)/2) : 0);
$command = system("convert $in -resize $size -crop {$width}x{$height}+{$xoff}+0 ".
"-colorspace RGB -strip -quality 90 $out");
// exec($command);
// echo $command;
}
$file = 'scan0001.pdf';
$out = 'scan0001_thumb.jpg';
makeThumbnail($file,$out);
? >
Getting Image magick working on XAMPP for Windows
After that you need to download php_imagick_dyn-Q16.dll from here.
if you did not find any php_imagick.zip file just refresh once on above URL.
Once you have download php_imagick_dyn-Q16.dll file put this in xampp/php/ext or php/extension folder.
Then open php.ini and add extension=php_imagick_dyn-Q16.dll.and comment extension=php_imagick.dll if it is already not commented .
And just restart your server.
Tuesday, April 6, 2010
Opening a file download dialog from a JavaScript function
function startDownload()
{
var url='http://server/folder/file.ext';
window.open(url,'Download');
}
< /script >
hide JavaScript errors from the user
return true;
});
PHP File Download
$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);