Tuesday 8 October 2013

How to Make XAMPP/Apache serve file outside of htdocs

    Go to PATH_TO_XAMPP\apache\conf\extra\httpd-vhosts.conf. Open this file and uncomment line 19. You can add your virtual host on line 36.

    <VirtualHost *:80>
        DocumentRoot C:\YOUR_NEW_PATH
        ServerName NEW_SERVER_NAME.localhost
        <Directory C:\YOUR_NEW_PATH>
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>


    Open your drivers hosts file at C:\Windows\System32\drivers\etc\hosts.

    Add

    127.0.0.1 NEW_SERVER_NAME.localhost #NEW_SERVER_NAME

    to the end of the file (before the Spybot - Search & Destroy stuff if you have that installed).

Save this file and Restart Apache and enjoy.

Sunday 17 February 2013

Getting the base url in codeigniter.

The current base url could be get easily by

<?php echo base_url(); ?>

But before doing so, you have to load the URL helper.

$this->load->helper('url');

Joomla 2.5, using JRegistry to extract the parameters of the categories.

The parameters of the categories can be easily extracted by the following method.



First of all, import the main registry class by,



 jimport( 'joomla.registry.registry' );

after that call the values of the categories as follows.
$query = "SELECT * FROM #__categories where parent_id != 1 ORDER BY id desc ";
$db = &JFactory::getDBO();
$db->setQuery($query);
$rowsc = $db->loadObjectList();
foreach($rowsc as $rowc)
{

}

then ,  in order to get the parameters, put the following code inside braces.

$par=$rowc->params;
$params = new JRegistry;
$params->loadJSON($par);

$image = $params->get('image');



and thats it

Disable GZip compression in Virtuemart.

Gzip compression is ideal for the improvement of the performance and speed of the site but in the situation that you want to disable the gzip compression in the virtuemart, follow the following steps.

Go to
administrator->components->com_virtuemart->classes

and open the file, mainframe.class.php

disable the line number 233 and 236.

Performing Insert, Update, Edit, Delete function in Joomla.

It doesent matter, which version, you are using, the following code will work. The code snippets given below canbe used freely in any place, like a model, view or a controller in joomla web programming.

Inserting Data:

$db =& JFactory::getDBO();
$query = "INSERT INTO #__users (name, username, email, password, gid) VALUES ('$name', '$username', '$email', '$password', '$gid')";
$db->setQuery($query);
$db->query();


Delete Data:

$db =& JFactory::getDBO();
$query = "DELETE FROM #__users WHERE id = '$id'";
$db->setQuery($query);
$db->query();


Update Data:

global $mainframe;
$db = & JFactory::getDBO();
$query = "UPDATE #__users SET name='$name' WHERE id='$uid'";
$db->setQuery( $query );
$db->query();


Select Data:

$query = "SELECT * FROM #__users where id='$uid' ORDER BY id desc ";
$db = &JFactory::getDBO();
$db->setQuery($query);
$rowsc = $db->loadObjectList();
foreach($rowsc as $rowc)
{
 $name=$rowc->name;
}

HTML5 multiple files upload with PHP

By using HTML5 approach, multiple files can be uploaded through a single click. Please look at the script below.


<input type="file" name="multifile[]" multiple="multiple">


 multiple="multiple"  is an HTML5 construct, to select multiple files at once. Now come to PHP.


$files=array();

$fdata=$_FILES['multifile'];

if(is_array($fdata['name'])){

for($i=0;$i<count($fdata['name']);++$i){

$files[]=array(

'name' => $fdata['name'][$i],

'tmp_name' => $fdata['tmp_name'][$i],

);   }      }

else $files[]=$fdata;

foreach ($files as $file) {

$target_path = $target_path . basename($file['name']);

move_uploaded_file($file['tmp_name'], $target_path)

}