Posts

Showing posts from 2012

How to upload a file in php with php validation of extension?

Simply copy and paste this code on your page And your input file name will be uploadedfile Like <input type="file" name="uploadedfile" /> and on submit of this page you will add this code $youruniqueid could be anything like userid or projected on the basis of this it will create folder for image upload $projId=$youruniqueid;    if(!empty($_FILES['uploadedfile']['name'])){     $imgExtension = array("jpg","jpe","jpeg","gif","png","GIF","JPG","JPEG","txt","pdf","PDF","docx","xlsx","pptx","pptm","doc","dot","xls","ppt");         $image_name = pathinfo($_FILES['uploadedfile']['name']);     $extension = strtolower($image_name['extension']);         if(in_array($extension,$imgExtension)){             $file_name = $_FILES['uplo

How to make a download link for download file in php

How to make a download link for download file in php or create a download link for download file in php? so here is the code and add base url according to your need   Create a php file download.php and paste this code in you php file $name = $_REQUEST['name']; // The file path where the file exists $filepath = 'http://www.site.com/files/'.$name; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //setting content type of page header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=".basename($filepath )); header("Content-Description: File Transfer"); //Read File it will start downloading @readfile($filepath); Now add this link in your file on your anchor tag like <a href=" http://www.site.com/download.php?name=file.png " >download link</a>

How to get date from a timestamp in mysql?

Image
How to get date from a timestamp in mysql? simple you can use FROM_UNIXTIME function and pass the parameter. my table name is  messages like this: SELECT FROM_UNIXTIME(`created`,'%Y-%m-%d') as date FROM `messages`

How to create thumb image of uploaded image in php?

Simply copy and paste this code in your page and call generate_thumbimage_thumbnail() somthing like that $path  = 'uploadediamgepath/myimage.png'; $save_path2  = 'project_image_thumb/thumb__myimage.png'; $iscopied2 = copy($path , $save_path2); if($iscopied2){ generate_image_thumbnail($path, $save_path2); } function generate_thumbimage_thumbnail($source_image_path, $thumbnail_image_path) { define('THUMBNAIL_IMAGE_MAX_WIDTH', 130); define('THUMBNAIL_IMAGE_MAX_HEIGHT', 130); list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path); switch ($source_image_type) { case IMAGETYPE_GIF: $source_gd_image = imagecreatefromgif($source_image_path); break; case IMAGETYPE_JPEG: $source_gd_image = imagecreatefromjpeg($source_image_path); break; case IMAGETYPE_PNG: $source_gd_image = imagecreatefrompng($source_image_path); break; } if ($source_gd_imag

How to get second last array in php?

lets take an example like this is your array Array ( [0] => 14802 Stony Plain Rd NW [1] => Edmonton [2] => AB T5N 3S5 ) and you want to get second last array " Edmonton" then simple use this array like this end ( $array ); $z = prev ( $array ); this is effective and you can get second last array. :)

How to get all record of yesterday from table in mysql?

Image
How to get all record of yesterday from table in mysql? if you are looking for sql query which will return you all record of yesterday. So please take a look on this query and replace the content according to your table Let your table is like this: So your query will be like this select id from tbl_download  WHERE date(download_date) = ADDDATE(current_date,-1) Happy coding :)

How to change the content of button of comment section in drupal?

How to change the content of button of comment section in drupal? if you want to change the content of button of comment box section submit button so follow this path yoursite/modules/comment and open this file  comment.module and search the keyword in this page  $form['submit'] = array('#type' => 'submit', '#value' => t('Save') replace the word Save to your desire word it will show on your comment section submit button.

How to remove "More information about formatting options" from drupal?

If you are looking for drupal help that.... How to remove "More information about formatting options" from drupal? so you come on  right place Follow your theme path choose your theme and open template.php Search this function phptemplate_filter_tips_more_info in your template.php file and check that if it is exist or not If exist so replace this function from last one function phptemplate_filter_tips_more_info() { return ''; } if not exist so please paste this function in your template.php anywhere where ever you want /** * Implementation of theme_filter_tips_more_info(). * Used here to hide the "More information about formatting options" link. */ function phptemplate_filter_tips_more_info() { return ''; } Thanks for read my blog :)

How to extract or fetch urls from text in PHP?

How to show url as a link from a text in php. this code will return you the link from a text . simply copy and paste this in you php file and call the function.  <?php             function make_clickable_string_url($text) {             return preg_replace_callback(             '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#',             create_function(             '$matches',             'return "<br/><a href=\'{$matches[0]}\'>{$matches[0]}</a>";'             ),             $text             );             }         ?> it will return you the string as well as return a link of url which exist in content

How can I to search in mysql within a table of comma-separated values?

I have a MySQL table which contains comma-separated values like 2,4,56,125 and i want to search record which have a particular value. so how can i search in mysql  simple copy and paste this code in your table and change your table name and field name and search keyword. SELECT * FROM table WHERE FIND_IN_SET(search_keyword , field_name)  like SELECT * FROM tbl_font WHERE FIND_IN_SET(2,cat_id)

How to use 301 url redirect in magento via htacess?

Make a .htaccess file on root of your magento paste this code on this file and change path of site..... <IfModule mod_rewrite.c> DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|media|skin|js|robots\.txt) RewriteRule ^typefaceselection.aspx$ /insignedesigncom/index.php/$1 [R=301,L] RewriteRule ^contact.aspx$ /insignedesigncom/index.php/contacts/$1 [R=301,L] RewriteRule ^thankyou.aspx$ /insignedesigncom/index.php/thankyou.aspx/$1 [R=301,L] </IfModule>

How to create custom script to convert ttf, otf or font file to png image via image magic script?

Image
Please check that image magick must be install on your server please note  /usr/bin/convert this path could be change which is define below of script to find out the path of image magick make a new php page and paste this code on this page <?php echo "<pre>"; system("type convert"); echo "</pre>"; ?> and run the page and can check that path is right or not if path is changed so please change the path from  /usr/bin/convert this path Create custom script to convert ttf, otf or font file to png image via image magic script? this script will generate the image of ttf ,otf, .pfm , pfb or font file. simply copy and paste this code on your browser. <?php set_time_limit(0); ini_set('max_execution_time', 0); if($_SERVER['HTTP_HOST']=="localhost") { $DB["dbName"] = "fontxs"; $DB["host"] = "localhost"; $DB["user"] = "root";

How to add jQuery email validation in my site?

Image
I want to add jQuery email validation in my site which is good looking also simply copy and paste this code for add jQuery email validation for your site <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1.7.1"); </script> <script type="text/javascript">     $(document).ready(function(){         try {         var domains =['hotmail.co.uk','yahoo.co.uk','yahoo.com.tw','yahoo.com.au','yahoo.com.mx','gmail.com','hotmail.com','yahoo.com','aol.com','comcast.net','msn.com','seznam.cz','sbcglobal.net','live.com','bellsouth.net','hotmail.fr','verizon.net','mail.ru','btinternet.com','cox.net','yahoo.com.br','bigpond.com','att.net',

How to remove index.php from Codeigniter URL or .htaccess and codeigniter not working?

After  after visiting so many sites  article i solve this problem that why its not working with index.php or why sub page links are not working without index.php I think all article has same copy and paste code on their website that's why you are wondering here and there ... try this code i think this will definitely work for you if your site is uploaded on root of website than open you htaccess from you root and paste this code on you htaccess Options +FollowSymLinks All -Indexes Options All -Indexes DirectoryIndex index.php RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] if your site is inside in sub-folder of any site like www.site.com/yoursitefolder/ so you have to paste this code on your htaccess file of your codeigniter site Options +FollowSymLinks All -Indexes Options All -Indexes DirectoryIndex index.php RewriteEngine on RewriteBase /yoursitefolder Rewrit

How can i remove 24X7 customer service image in magento?

Follow the path which is define below You need to comment all code in app/design/frontend/Your theme/default/template/callouts/left_col.phtml file now refresh the cache and check its works pefectly :)

How to Show or Hide File Extensions in window 7 or window xp?

Image
How to Show or Hide File Extensions in window 7 or window xp? This is main problem that you can not see the extension of file in operating system on window wista and window 7 and you can not change the extension by rename the file. For window 7 open any folder press alt button a top navigation will show on top. Click on tools as image shows below 1. Click on folder option 2. Click on View Tab 3. Click Show or hide file extensions . 4. In the Folder Options box that appears, clear the checkbox next to Hide extensions for known file types , then click OK .

why Images are not Showing on Frontend as well as Backend on Godaddy Server in magento?

Images are not Showing on Frontend as well as Backend on Godaddy Server in magento recent i transfer my project one to another server every thing is working fine on my local server but when i upload this project on another server images are not showing on frontend and  backend of products. I surfed many magento help sites with many of the suggestions and tried everything but that that was not working for me and finally after a lot of hectic trials i got the solution for it. Just Rename your .htaccess file inside the /media directory to .htaccess-old. This will absolutely work for your site. if its works for you don't forget to say thanks to this blog :)

How to add custom design twitter feed in php website?

If you are looking for twitter feed which you can customized your self then Simple copy and paste this code in your page for twitter feed and change the twitter username <?php     $username = "xyz"; // change the username     $limit = 5;     $feed = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit;     $tweets = file_get_contents($feed);   $tweets = str_replace("&", "&", $tweets); $tweets = str_replace("<", "<", $tweets); $tweets = str_replace(">", ">", $tweets); $tweet = explode("<item>", $tweets);     $tcount = count($tweet) - 1; for ($i = 1; $i <= $tcount; $i++) {     $endtweet = explode("</item>", $tweet[$i]);     $title = explode("<title>", $endtweet[0]);     $content = explode("</title>", $title[1]); $content[0] = str_replac

How to add a text counter in textarea or Setting a maxlength on a textarea?

if you want to add text counter your textarea and set the Setting a maxlength on a textarea. so simply add this code in file and run the file in your browser <form name="textcount" id="textcount"> <textarea cols="60"  rows="12" class="input_compose_textarea" id="description" name="description" onkeypress="textCounter(this,this.form.counter,500);" onblur="textCounter(this,this.form.counter,500);"></textarea> <br/> Max length - <input    type="text" readonly="readonly"    name="counter"    maxlength="3"    size="3"    value="500"    onblur="textCounter(this.form.counter,this,500);"> char remaining. </form> <script type="application/javascript"> function textCounter( field, countfield, maxlimit ) { if ( field.value.length > maxlimit ) { field.value = field.va

How to Check if current page is Homepage or not in magento?

Simply add this code in your page this code will check if current page is Homepage or not in magento. <?php if($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))): echo "yes homepage of magento"; else: echo "this is not Homepage"; endif; ?>

How to remove right column from product details page in magento?

go to this directory app/design/frontend/base/default/layout/ open catalog.xml and search  <label>Catalog Product View (Any)</label> you can find this line around 180 line of this page code will be like this <catalog_product_view translate="label">         <label>Catalog Product View (Any)</label>         <!-- Mage_Catalog -->         <reference name="root">             <action method="setTemplate"><template>page/2columns-right.phtml</template></action>         </reference> change 2columns-right.phtml to 1column.phtml  <catalog_product_view translate="label">         <label>Catalog Product View (Any)</label>         <!-- Mage_Catalog -->         <reference name="root">             <action method="setTemplate"><template>page/1column.phtml</template></action>         </reference&

How to get the path of downloadable product's file of associated product or group product which was upload during add downloadable product?

How to get the path of  downloadable product's file of associated product or group product which was upload during add downloadable product? This will return you full path of downloadable product  $file =''; $home_url = Mage::helper('core/url')->getHomeUrl(); $static_path = $home_url."media/downloadable/files/links"; $productLinks = $ $product ->getTypeInstance(true)->getLinks($product); foreach($productLinks as $key=>$val) {       $val = trim($productLinks[$key]->link_file);         if($val!='')         {         $file = $val;         }         else         {         $file = '';         } } echo $file_path = $static_path.$file;

HOW TO GET GET BASE URL, SKIN URL, GET MEDIA URL, GET STORE URL AND OTHER URLS IN MAGENTO?

HOW TO GET  GET BASE URL, SKIN URL, GET MEDIA URL, GET STORE URL AND OTHER URLS IN MAGENTO? HERE IS SOME USEFULL URL FOR YOU WHICH CAN HELP YOU TO USE THE DEFINE URL IN MAGENTO HOPE THIS WILL HELP YOU. To get Media URL {{media url='/sampleimage.jpg'}} To get Store URL {{store url='mypage.html'}} To get Base URL {{base url='yourstore/mypage.html'}} TO Retrieve URL path in PHTML Note: In editing PHTML don't forget to enclode the following code with PHP tag Not secure Skin URL: <?php echo $this->getSkinUrl('images/sampleimage.jpg') ?> Secure Skin URL <?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?> Get  Current URL $current_url = Mage::helper('core/url')->getCurrentUrl(); Get Home URL $home_url = Mage::helper('core/url')->getHomeUrl(); Get Magento Media Url Mage::getBaseUrl(

How to know product type in magento?

How to know product type in magento that product is group or simple or downloadable. echo $product->getTypeId();

How to get the id of associated products in magento from the array of associated products?

Get the id of associated products in magento from the array of associated products. i was getting rid that i have array of associated product but unable to get the id of associated product. after so much search i found this solution check this it will works for you .... $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product); foreach($associatedProducts as $assoc_id) { $aid = $assoc_id->getId(); echo "id of associated products is = ".$aid; echo "<br/>"; }

How to get the array of associated product of group product in magento?

For get the array of associated product of group product in magento you to add simple this line in code where you are getting group product details. $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product); print_r( $associatedProducts ); it will return to you all associated products array of group product now you can use this array as you want. and you want to get the associated product ids only then you can simple add this like below above code foreach($associatedProducts as $assoc_id) { $aid = $assoc_id->getId(); echo "id of associated products is = ".$aid; echo "<br/>"; }

How to get count of cart item in magento?

simply copy and paste where you want to get count of cart item in magento <?php $mageFilename = 'app/Mage.php'; require_once $mageFilename; umask(0); Mage::app(); Mage::getSingleton('core/session', array('name'=>'frontend')); $session = Mage::getSingleton('checkout/session'); $output = ""; foreach ($session->getQuote()->getAllItems() as $item) {     $output .= $item->getQty() . "<br>"; } print $output; ?>

How to create a page which show only subcategory or how to show all category on one page in magento?

Go to the admin Now follow the step CMS->PAGES->Add new page Insert these data in the form Step 1:- insert in Page Information tab Titile-> categories URL Key *-> categories Status *->Enabled Step 2:- insert in Content Content Heading->anything according to you and paste this code in the textarea box {{block type="catalog/navigation" name="catalog.categories" template="catalog/navigation/category_listing.phtml"}} Step 3:- select in Page Layout Layout *->select   2 columns with right bar After this save the page Now add new page and in this directories App/design/frontend/base/default/templates/catalog/navigation/ category_listing.phtml And add this code in this page <?php $_category  = $this->getCurrentCategory();  $collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id); $helper     = Mage::helper('catalog/category'); ?>

How to show Currency Options drop down on homepage or header in magento?

show Currency Options drop down on homepage or header in magento? and if not showing  Currency Options drop down somewhere so follow these steps. - Follow these steps to show store specific currency:- - Go to System -> Configuration -> GENERAL -> Currency Setup - In left sidebar at top, you will see “Current Configuration Scope” - Select your desired store from the selection list - Now, under “Currency Options“, you will see “Default Display Currency” - Select your desired currency from the selection list You are done. In frontend, select the store for which you did the above changes. You will see the price in your desired currency. and put this line of code where u you want to display currency converter <?php echo $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml(); ?>

How to show category on right side or left side in magento?

First of all you have to create a new block in xml to show the category Navigate to /app/design/frontend/default/default/layout/catalog.xml Open this page and search this keyword " Default layout, loads most of the pages " and put this code in block <reference name="right"> <block type="catalog/navigation" name="catalog.righthomenav" template="catalog/navigation/right_home_nav.phtml" /> </reference> you can change layout position in mageto to change the  reference name as ( right, left, footer, etc ) create a new and directory like this path  /app/design/frontend/default/default/template/ catalog/navigation/ right_home_nav .phtml and paste this code in that in new page  right_home_nav .phtml <h2>Browse</h2> <div class="block"> <ul id="nav_category" class="nav_category"> <?php foreach ( $this -> getStoreCategories ( ) as $_category ) :

How to show featured products on home page in magento?

If you want to show featured products on home page in magento so here is code for you... IF you still have not add featured attribute in magento so first of all you have to add arrtibute in  Manage Attributes Step 1: Create new Featured attribute Create a new attribute by going to Catalog > Attributes > Manage Attributes > Add New Attribute. Attribute Properties Attribute Identifier: featured Scope: Store View Catalog Input Type for Store Owner: Yes/No Unique Value (not shared with other products): No Values Required: No Input Validation for Store Owner: None Apply To: All Product Types Front End Properties Use in quick search: No Use in advanced search: Yes Comparable on Front-end: No Use In Layered Navigation (Can be used only with catalog input type ‘Dropdown’): No Visible on Catalog Pages on Front-end: Yes Manage Label/Options Default: Featured Product Save the new attribute and go to Catalog ? A