Thursday, October 29, 2009

Installing PHPUNIT2 on Windows system

The following post gives u a detail information about installation of PHPUNIT2 into your wamp server on windows system

Step1. Check your wamp has installed properly on windows system. If it is then open wamp folder and go to the php folder and you should find go-pear.bat file

Step2. open command prompt and go to php directory in wamp

C:\> cd wamp\php

If your wamp structure is different then check for following path

C:\>cd wamp\php\php5.5

But here I am following the wamp\php path for installation. if yours is different than please follow as in your wamp instead of “wamp\php”






Step3.
Run go-pear.bat batch file from this place for complete installation of pear into your wamp php server

C:\cd wamp\php>go-pear.bat

Here it will ask you for some conformation if you don’t know then go with the default selection like [system | local]system:”select system here”

Complete the process like this with all default selection

Step4. once the installation is completed run PEAR_ENV.reg file from this place so that environment variable can be created to the for the user running wamp server. Then only your able to access pear files anywhere in the document root folder

NOTE:if your unable to create environment variable then manually you can create with following steps

Click on system properties->select advanced->Environment variables

Here you can add directory path variable “ c:\wamp\php

Step5. Once your pear setup is over you must register your phpunit channel with the pear registry

C:\wamp\php>pear channel-discover pear.phpunit.de

Step6. Once the register is over now your able to install all supporting packages from the phpunit channel

C:\wamp\php>pear install pear/phpunit2

Then it may ask you to install all supporting packages for phpuint like

C:\wamp\php>pear install pear/benchmark

C:\wamp\php>pear install pear/console_Getopt

Step7. Now you will find phpunit folder under php\pear folder where all subfolder with all utilities will be there now your phpunit as configured and its ready to use in your project

Thursday, October 8, 2009

Creating recursive folders in linux server through php script

Creating recursive folders in linux server through php script

while creating directory inside your root folder or in any folder through php script you should take care of the following steps.

which may gives you problem by not creating folder under any root folder

In some linux server if your warrings are off then it won’t give warring msg if any following error raise

this type of problem you may get when you’re trying to create folder recursively

Here I am giving the list of problem

1)permission

2)owner permission

3)group permission

4)most important safe mode ON in linux server

If your having problem of not creating folder under any root folder or under any other folder (permission problem)

-pls check the root permission for the folder under which your trying to create dir through php

Or through php itself you can able to change the permission for the folder like this

$chmod_value = chmod(“/root/folder/”,0755);

-don’t giv full permission for the source folder where your trying to create max 755 is enough.

-if your not able to create due to owner permission then

-pls check under which owner your trying to create the folder and you can change the owner of the folder to the current logged in

chown (“root/folder/”,"owner_name");//giv the proper owner name

--if your not able to create due to group permission then

-pls check under which group your trying to create the folder and you can change the group of the folder to the current logged in

chgrp (“root/folder/”,"group_name");//giv the proper group name

- if you’re not able to create due to safe mode on

-if your trying to create recursive folders in linux server then u must take care of safemode setting inside your config file

-if your server safemode is ON then your unable to create recursive folders

It wont alow you to change the permission through php script by default it vl take its own apache as user and group as apache

-to overcome this prblem you can try this by changing the safemode off through php like this

ini_set("safe_mode",0);

-if your using .htaccess file at ur root level then you can try the by setting

Default safe_mode off ;

-in worst condition if the above 2 way don’t work then you have to switch of the safe mode directly inside your apache server configure so by this your php should be able to create folder inside linux server


Tuesday, October 6, 2009

Uploading Multiple Files in PHP without ajax or jquery

Uploading Multiple Files in PHP without ajax or jquery
Here iam giving simple and very efficient php multiple file uploader in single submit with the option of deleting uploaded files from the list
And this uploader works in both LE and Firefox very well
While uploading multiple file after adding files into the list before uploading u can able to alter the list in this uploader, and in list only the file names will be visible
And inside javascript u can change the images and buttons based on your require
The Steps installing this uploader into ur php file pls follow the steps below
Step 1
Paste this following javascript inside ur html file or in separate javascript file which should be include in html
function MultiSelector( list_target, max ){
// Where to write the list
this.list_target = list_target;
// How many elements?
this.count = 0;
// How many elements?
this.id = 0;
// Is there a maximum?
if( max ){
this.max = max;
} else {
this.max = -1;
};


/**
* Add a new file input element
*/
this.addElement = function( element ){
// Make sure it's a file input element
if( element.tagName == 'INPUT' && element.type == 'file' ){ // Element name -- what number am I?
element.name = 'ufile[]';//this u can set if your making use of array in the list
element.id='ufile[]'; // Add reference to this object
element.multi_selector = this;
// What to do when a file is selected
element.onchange = function(){
// New file input
var new_element = document.createElement( 'input' );
new_element.type = 'file';
new_element.size = '48';
// Add new element
this.parentNode.insertBefore( new_element, this );
// Apply 'update' to element
this.multi_selector.addElement( new_element );
// Update list
this.multi_selector.addListRow( this );
// Hide this: we can't use display:none because Safari doesn't like it
this.style.position = 'absolute';
this.style.left = '-1000px';
};
// If we've reached maximum number, disable input element
if( this.max != -1 && this.count >= this.max ){
element.disabled = true;
};
// File element counter
this.count++;
// Most recent element
this.current_element = element;
} else {
// This can only be applied to file input elements!
alert( 'Error: not a file input element' );
};
};
/**
* Add a new row to the list of files
*/
this.addListRow = function( element ){
// Row div
var new_row = document.createElement( 'div' );
// Delete button to add the button
var new_row_button = document.createElement( 'input' );
new_row_button.type = 'button';
new_row_button.value = 'Delete';
new_row_button.align = 'absbottom';
new_row_button.style.cursor = 'hand';
// Delete image instead of button you can put image with this following code
/*var new_row_button = document.createElement('img');
new_row_button.src = images/image_namegif';
new_row_button.alt = 'Delete';
new_row_button.height = '14';
new_row_button.align = 'absbottom';*/
// References
new_row.element = element;
// Delete function
new_row_button.onclick= function(){
// Remove element from form
this.parentNode.element.parentNode.removeChild( this.parentNode.element );
// Remove this row from the list
this.parentNode.parentNode.removeChild( this.parentNode );
// Decrement counter
this.parentNode.element.multi_selector.count--;
// Re-enable input element (if it's disabled)
this.parentNode.element.multi_selector.current_element.disabled = false;
// Appease Safari
// without it Safari wants to reload the browser window
// which nixes your already queued uploads
return false;
};
// Add button
new_row.appendChild(new_row_button);
// Set row value
var arr = element.value.split("\\");
var out_count =arr.length;
if(navigator.appName == "Microsoft Internet Explorer") {
var new_label = document.createElement('label');
new_label.align = 'absmiddle';
new_label.innerHTML = ' '+arr[out_count - 1];
//new_row.innerHTML += arr[out_count - 1];
new_row.appendChild(new_label);
//new_row.innerHTML = new_row_button;
}
else
{
var new_label = document.createElement('label');
new_label.align = 'absmiddle';
new_label.innerHTML = ' '+element.value;
new_row.appendChild(new_label);
}
//new_row.appendChild(new_row_button);
// Add it to the list
this.list_target.appendChild( new_row );
};
};
Step 2
Paste this code in place of where you want to display the upload browse button and the list of file uploaded
Hav form with action
<form action="upload.php"   method="post" id="uploadfrm" name=" uploadfrm " enctype="multipart/form-data">
<div >
<input id="ufile[]" size="48" type="file" value="" name="file_1" />
</div>
<div id="files_list"> </div>//here you can see the list of files uploaded 
</form>
Step 3
In upload.php you can access this files data in this way
if (count($_FILES ['ufile']['name'])) {
for($i=0;$i
{
$root_path= //root path of the upload folder where you created
$path[$i]= $root_path."/upload/".$_FILES['ufile']['name'][$i];//where you want to upload the your  files(path) $file_names[$i] = $_FILES['ufile']['name'][$i];
$copy_done[$i] = copy($_FILES['ufile']['tmp_name'][$i], $path[$i]);
}
if($copy_done)
{
    echo "uploaded"; 
}
}