Category Archives: Php

Vitual Host in Xampp

It is a very important for symfony developer to use virtual host.

I am going to give a simple help here. Any further help will be appreciate …

NameVirtualHost *:80


<VirtualHost *:80>
    DocumentRoot "E:/WebSites/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "E:/WebSites/xampp/htdocs/kh3.3.0"
    ServerName localhost.kohana.dev
    <Directory "E:/WebSites/xampp/htdocs/kh3.3.0">
	Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "E:/WebSites/xampp/htdocs/sf-1419/jobeet/web"
    ServerName www.jobeet.com.localhost
  DirectoryIndex index.php
  <Directory "E:/WebSites/xampp/htdocs/sf-1419/jobeet/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf E:\WebSites\xampp\htdocs\sf-1419\jobeet\lib\vendor\symfony\data\web\sf
  <Directory "E:/WebSites/xampp/htdocs/sf-1419/jobeet/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

In C:\Windows\System32\drivers\etc hosts

127.0.0.1       localhost
127.0.0.1       localhost.kohana.dev #change to match your Virtual Host.
127.0.0.1       www.jobeet.com.localhost #change to match your Virtual Host.

Generate Order Number

That’s what I’ll do. As for formatting the number, here’s what I did…

$id_num = 5;
$order_num = sprintf("NSC-%010d", $id_num);
echo $order_num;

That gives me a number like…

NSC-0000000005

So if the $id_num is 2044 then the zero spaces will account for the larger id number and give me…

NSC-0000002044

Figured I’d post it, in case anyone else needed something similar. Thanks again!

Thanks to wilhud

Fource to download a file in php as well as in joomla 2.5

I am wondering how to download forcefully a file using php
I am using this code. If any one has more better code please share with us

           $filename = $path . DS . $this->item->file;die();
            if (is_file($path . DS . $this->item->file))
            {
                if (file_exists($filename))
                {
                    header('Content-Description: File Transfer');
                    header('Content-Type: application/octet-stream');
                    header('Content-Disposition: attachment; filename=' . basename($filename));
                    header('Content-Transfer-Encoding: binary');
                    header('Expires: 0');
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    header('Pragma: public');
                    header('Content-Length: ' . filesize($filename));
                    ob_clean();
                    flush();
                    readfile($filename);
                    exit;
                }
            }

Here file path will be like as D:\xampp\htdocs\jm-dmrd\file\noticeboard\pdf\New_Microsoft_Word_Document-.docx

Thanks

Image resize in php

Here there are some basic help for image resizing code in php


function get_width($mages) {
    list($img_width, $img_height) = getimagesize($mages);
    return $img_width;
}

function get_height($mages) {
    list($img_width, $img_height) = getimagesize($mages);
    return $img_height;
}

function get_ratio($mages) {
    list($img_width, $img_height) = getimagesize($mages);
    return $img_width / $img_height;
}

function get_type($mages) {
    list($img_width, $img_height, $type, $attr) = getimagesize($mages);
    return $type;
}

function get_mime($mages) {
    $array = getimagesize($mages);
    return $array['mime'];
}

function resize($width, $height, $img) {

    $old_image = imagecreatefromjpeg($img);
    $image_width = imagesx($old_image);
    $image_height = imagesy($old_image);
    $image_aspect_ratio = $image_width / $image_height;
    $image_type = get_type($img);
    $image_mime = get_mime($img);

    $new_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
    if(file_exists('resized-imges/sample2.jpg'))
        unlink('resized-imges/sample2.jpg');
    imagejpeg($new_image, 'resized-imges/sample2.jpg', 100);

    imagedestroy($new_image);
}

function resizeToHeight($height, $img) {

    $old_image = imagecreatefromjpeg($img);
    $image_width = imagesx($old_image);
    $image_height = imagesy($old_image);
    $ratio = $height / $image_height;
    $width = $image_width * $ratio;
    resize($width, $height, $img);
}

function resizeToWidth($width, $img) {
    $old_image = imagecreatefromjpeg($img);
    $image_width = imagesx($old_image);
    $image_height = imagesy($old_image);
    $ratio = $width / $image_width;
    $height = $image_height * $ratio;
    resize($width, $height, $img);
}

$img = ('images/Shrek2-3.jpg');

resizeToWidth(600, $img);

Water mark on a image in php

By Image ::


$watermark = imagecreatefrompng('select_sport.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg('photo/Chrysanthemum.jpg');
$size = getimagesize('photo/Chrysanthemum.jpg');
$dest_x = $size[0] - $watermark_width - 50;
$dest_y = $size[1] - $watermark_height - 50;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image, "photo/" . 'ok.jpg');  
imagedestroy($image);
imagedestroy($watermark);

By Text ::

$font_path = "ARIAL.TTF"; // Font file
$font_size = 20; // in pixcels
$water_mark_text_2 = 'http://www.sample.com'; // Watermark Text

$oldimage_name = 'photo/Chrysanthemum.jpg';
list($owidth,$oheight) = getimagesize($oldimage_name);
$width = $owidth; $height = $oheight; 
$image = imagecreatetruecolor($width, $height);
$image_src = imagecreatefromjpeg($oldimage_name);
imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$blank = imagecolorallocate($image, 255, 255, 255);
$size = getimagesize($oldimage_name);
$dest_x = $size[0] - 350;
$dest_y = $size[1] - 50;
imagettftext($image, $font_size, 45, $dest_x, $dest_y, $blank, $font_path, $water_mark_text_2);
imagejpeg($image, "photo/" . 'ok.jpg'); 
imagedestroy($image);

Check form field empty before submit

<script type="text/javascript" language="JavaScript">
function nameempty()
{
    if ( document.form.first_name.value == '' )
    {
        alert('No Name was entered!')
        return false;
    }
	 if(document.form.last_name.value == '')
	{
		alert('No Last name entered!')
		return false;
	}
	 if(document.form.address1.value == '')
	{
		alert('No Address entered!')
		return false;
	}
	 if(document.form.city.value == '')
	{
		alert('No City entered!')
		return false;
	}
	 if(document.form.zip.value == '')
	{
		alert('No Zip code entered!')
		return false;
	}
 	 if(document.form.state.value == '')
	{
		alert('No State entered!')
		return false;
	}
	 if(document.form.country.value == '')
	{
		alert('No Country entered!')
		return false;
	}


}
</script>
 
<form action="paypal.php" method="post" name="form" onSubmit="return nameempty();">
Fist Name:<input type="text" name="first_name" value=""><br />
Last Name:<input type="text" name="last_name" value=""><br />
Address1:<input type="text" name="address1" value=""><br />
Address2:<input type="text" name="address2" value=""><br />
City: <input type="text" name="city" value="" /> <br/>
State:<input type="text" name="state" value=""><br />
<input type="hidden" name="item_name" value=""><br/>
<input type="hidden" name="amount" value=""><br/>
Zip:<input type="text" name="zip" value=""><br />
Country:<input type="text" name="country" value=""><br />


<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" >
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Create a form and send mail using loop and on page submit

<div class="box  base-mini" style="background:#E7F1F4">
<div class="head">
   <h4>Send Mail</h4>
 </div>
 <p style=" color:#24394C; font-family:Arial; font-size:10px; font-weight:bold;" align="center">If you did not find the cell phone you are looking for</p>
<form method="post" action="">
<table width="180px">
<tr>
<td style=" white-space:nowrap" >Cell:</td><td><input size="18" type="text" name="name"/></td>
</tr>
<tr>
<td style=" white-space:nowrap">Model:</td><td><input  size="18"type="text" name="number"/></td>
</tr>
<tr>
</tr>
<tr><td style=" white-space:nowrap">Email:</td><td><input  size="18"type="text" name="your"/></td>

</tr>
<tr><td align="right" colspan="2" valign="bottom"><input type="submit" name="submit" value="Send"/></td>
</tr>
</table>
</form>

<?php
if (isset($_POST['submit'])){
	if ($_REQUEST['name'] != NULL && $_REQUEST['number'] != NULL && $_REQUEST['your'] != NULL ) {
	$va1 = $_POST['name'];
	$va2 = $_POST['number'];
	$va3 = $_POST['your'];
 
 	$to = array('imran@liveoutsource.com','midpart50@gmail.com');
for($i=0;$i<=1;$i++)
{
	$to1 = $to[$i];
	$subject = "New Mobile For Your Store";
	$message ="Cell Name: " .$va1.",  "."Model: ".$va2;
	echo $to1;
	$from = $va3;
	$headers = "From: $from";
	mail($to1,$subject,$message,$headers);
}
	echo  '<p style="color:#236E2D" align="center" >'."Mail Sent".'</p>';
	}
	if ($_REQUEST['name'] == NULL || $_REQUEST['number'] == NULL || $_REQUEST['your'] == NULL ) {
	echo  '<p style="color:#FF0000" align="center" >'."Plz Enter Missing Field ".'</p>';
	 }

}
?>
</div>
%d bloggers like this: