Posts

Showing posts with the label PHP

CodeIgniter Registration form

Image

Multiple image uplode with fixed size / thumb image code

Please understand code. May be for fresher it will difficult but all the things is not possible. Note : 1 . Path variable metion in your contant files. 2 . change 640 size as your depend size. 3. This code you can use for thumb images also function multiImageUpload ($Menu_Name, $Car_Name, $Car_Id){         global $PATH_IMAGE;                 //echo '<pre>'; print_r(sizeof($_FILES['ufile']['name']));                         for($i = 0; $i<=sizeof($_FILES['ufile']['name']); $i++)         {             $image=$_FILES['ufile']['name'][$i];                    $img_name = strtolower($Menu_Name) . substr($Car_Name, 0, 6);                                     if ($image)             {                 $filename = stripslashes($_FILES['ufile']['name'][$i]);                            $extension = getExtension($filename);                 $extension = strtolower($extension);                   

MVC Architechture...

Model A model is an object representing data or even activity, e.g. a database table or even some plant-floor production-machine process. The model manages the behavior and data of the application domain, responds to requests for information about its state and responds to instructions to change state. The model represents enterprise data and the business rules that govern access to and updates of this data. Often the model serves as a software approximation to a real-world process, so simple real-world modeling techniques apply when defining the model. The model is the piece that represents the state and low-level behavior of the component. It manages the state and conducts all transformations on that state. The model has no specific knowledge of either its controllers or its views. The view is the piece that manages the visual display of the state represented by the model. A model can have more than one view. Note that the model may not necessarily have a persistent da

how to make virtual directory in xampp?

 C:\xampp\apache\conf\extra\httpd-vhosts.conf Add following code in end.  <VirtualHost *>     DocumentRoot "D:\www\foldername"     ServerName local.sitename         <Directory "D:\www\foldername">         Order allow,deny         Allow from all     </Directory>   </VirtualHost> C:\WINDOWS\system32\drivers\etc\hosts 127.0.0.1       local.newsite

create thumb image using php

<?php function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) {   // open the directory   $dir = opendir( $pathToImages );   // loop through it, looking for any/all JPG files:   while (false !== ($fname = readdir( $dir ))) {     // parse path for the extension     $info = pathinfo($pathToImages . $fname);     // continue only if this is a JPEG image     if ( strtolower($info['extension']) == 'jpg' )     {       echo "Creating thumbnail for {$fname} <br />";       // load image and get image size       $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );       $width = imagesx( $img );       $height = imagesy( $img );       // calculate thumbnail size       $new_width = $thumbWidth;       $new_height = floor( $height * ( $thumbWidth / $width ) );       // create a new temporary image       $tmp_img = imagecreatetruecolor( $new_width, $new_height );       // copy and resize old image into new image  

Uploading files with PHP

Upload an image or file to your server without using your FTP. Step 1: Open a web editor, then paste this <form action="upload.php" method="post" ENCTYPE="multipart/form-data"> File: <input type="file" name="file" size="30"> <input type="submit" value="Upload!"> </form> Then save it as form.php Step 2: Open a web editor once again, and paste this code: <?php $uploaddir = "uploads"; // Where you want the files to upload to if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']); } print "Your file has been uploaded successfully!"; ?> Save it as upload.php Step 3: Upload these to files onto your website using any ftp program. Step 4: Upload a folder called uploads and CHMOD it to 0777

PHP send email with image attachment ?

How to send Email attachment using core php email function. You file has been sent to the email address you specified. Make sure to check your junk mail! Click here to return to mysite.com. "; } else { die("Sorry but the email could not be sent. Please go back and try again!"); } ?> Here we have created a new example where you can able to send email using PHPMailer Class.

How to use constant variable?

Once you declared constant variable you just need to include that file and use variables <?php DEFINE('PATH','http://www.google.com'); echo PATH; ?> output  http://www.google.com

How to redirect first page to another page?

Here is a simple example how to use header() function to redirect page from one page to another. <?php //Redirect page from one page to another page. header("Location:http://www.google.com"); ?>

how to store and retrieve array from Session variable using php?

Here is simple code to illustrate use of session to store array that can be used in other script. <?php session_start(); $_SESSION['type'] = "ikhlaque"; $_SESSION['colors'] = array("black", "silver", "red"); if (isset($_SESSION['type']) && isset($_SESSION['colors'])) { echo "You would like a " , $_SESSION['type'] , " in " , implode(" and ", $_SESSION['colors']); } ?> It will output 'You would like a ikhlaque in black and silver and red'

how to delete multiple selected data in php?

sample.php <?php if($_POST['delete']=='Delete Slected'){     for($i=0;$i<$count;$i++){         $del_id = $checkbox[$i];         $sql = "delete from need_workshop where id='$del_id'";         $result = mysql_query($sql);     } } ?> <form name="frmdelete" method="post" action=""> <table width="100%"> <tr> <td colspan="8" align="Left" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete Slected"></td> </tr> <tr>  <td id="heading">Select</td>  <td id="heading">Name</td>  <td id="heading">College</td>  <td id="heading">Contact</td>  <td id="heading">E-mail</td>  <td id="heading">Worksdop Type</td>  <td id="h

How to Upload Image using PHP?

Here you can learn Upload Image and at a same time information stored into database. <?php //define a maxim size for the uploaded images in Kb  define ("MAX_SIZE","100"); //This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.  function getExtension($str) {          $i = strrpos($str,".");          if (!$i) { return ""; }          $l = strlen($str) - $i;          $ext = substr($str,$i+1,$l);          return $ext;  }  function UploadImage(){ //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //if it is not empty if ($image) { //get the original name of the file from the clients machine $filename = stripslashes($_FILES['image']['name']); //get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strt

PHP Interview questions

1 .   Would you initialize your strings with single quotes or double quotes? - Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution. 2. How come the code <?php print "Contents: $arr[1]"; ?> works, but <?php print "Contents: $arr[1][2]"; ?> doesn’t for two-dimensional array of mine?  - Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.

crontab example in linux

Find Below example for crontab linux example. # Minute Hour Day of Month Month Day of Week Command # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) 0 4 1 * 0 /usr/bin/example This line executes the "example" command at 4AM on the 1st of every month that a Sunday falls on. The -l option causes the current crontab to be displayed on standard output. The -r option causes the current crontab to be removed. The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.  

PHP use of array in form ?

Here is a simple example how to use array in html form element to store multiple value under single name. <html> <head> <title>Use of array in form</title> </head> <body> <h1>Use of array in form</h1> <?php if(isset($_REQUEST['artists'])){ ?> your favourite artists: <?php echo implode($_REQUEST['artists']," , "); } else { ?> <form method="post"> Select your favourite artists: <br /> <select name="artists[]" multiple="true"> <option value="Amitabh Bachan">Amitabh Bachan</option> <option value="Shahrukh Khan">Shahrukh Khan</option> <option value="Aamir Khan">Aamir Khan</option> <option value="Salman Khan">Salman Khan</option> <option value="Ajay Devgan">Ajay Devgan</option> </select< <input type="submit"

Add forcibly www in the beginning of the url using HTACCESS ?

Add following code in your .htaccess file. RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC] RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301

How to increase max upload file size limit using HTACCESS ?

By default,most server allow max 2MB file size to upload on server.but in some case you have to change to allow more than 2MB files to upload.just add following code in .htaccess file. eg. upload_max_filesize=20MB