Pages

Unzip an uploaded file using php

If you dont have shell access to your server and need to unzip a file on your php server you can use the script below:

Example 1. Extract all entries


<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
$zip->extractTo('/my/destination/dir/');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>

Example 2. Extract only two entries


<?php
$zip = new ZipArchive;
$res = $zip->open('test_im.zip');
if ($res === TRUE) {
$zip->extractTo('/my/destination/dir/', array('pear_item.gif',
'testfromfile.php'));
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>


ZipArchive::extractTo

ZipArchive::extractTo -- Extract the archive contents

Description

mixed ZipArchive::extractTo ( string destination [, mixed entries] )
Extract the complete archive or the given files to the specified destination.

Parameters

destination - Location where to extract the files.
entries - The entries to extract. It accepts either a single entry name or an array of names.
Return Values - Returns TRUE on success or FALSE on failure.

PHP Cron Jobs with cPanel

Cron jobs allow you to automate certain commands or scripts on your server to complete repetitive tasks automatically. A cron job allows you to run a certain command at times set by the job. For example, you could set a cron job to delete temporary files every week so that your disk space is not being used up by those files.

1. you can get started with the simple cron tool built into cPanel.url:

https://www.yoursite.com:2083/frontend/x/cron/simplecron.html?

To access the Cron Jobs Menu, click on the corresponding icon located on the main screen of your cPanel interface.


2. The cron email section of the Cron Jobs interface allows you to specify the email address where you would receive an email each time a cron job is ran for your account.

If you do not want an email to be sent for an individual cron job you can redirect the command's output to /dev/null like this:
mycommand >/dev/null 2>&1

You can enter the desired email address in the text box and click the Update Email button to apply the changes.


3. Next section of the Cron Job interface is where you actually set your cron jobs.
Once ready setting up the cron job click the "Add New Cron Job" button and it will be saved and activated for your account.


Want to select an option from all the select boxes. Remember to select an option in each box.

If you want something to run every day at 4AM:
select Minute: 0; Hour: 4; Day: Every; Month: Every; Weekday: Every;


4. The bottom part of the Cron Jobs interface will allow you to edit or delete existing cron jobs.

The command to run:
php -q /home/(username)/public_html/(scriptname).php


Paypal "Buy Now" Button HTML Code

When you use PayPal's Buy Now Buttons, you can sell individual items from your website, or even using a link in an email! Buy Now Buttons is a low–cost way for you to accept credit card and bank account payments, and can be fully integrated with your website in a few easy steps.

The example code below shows the minimum information you need to create a Buy Now button (in this case, to purchase a teddy bear):




<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me@mybusiness.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Teddy Bear">
<input type="hidden" name="amount" value="12.99">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>





Dynamic Button Generation

If you dynamically generate portions of your site, save time by updating the variables with information from your database. To use the button above for a different item, edit the values for two variables:
  • item_name
  • amount

Show message in TextBox


JavaScript can be used to display some information to the users.When user click on the textbox,
message will be hidden.very simple one but can be used in HTML forms without using labels.it will
increase the look and feel of the web page.


<script language=JavaScript>

function clear_username()
{
if (document.text_form.u_input.value == "username")
document.text_form.u_input.value = "";

if (document.text_form.input.value =="")
document.text_form.input.value ="password";
}

function clear_password()
{
if (document.text_form.input.value == "password")
document.text_form.input.value = "";

if (document.text_form.u_input.value == "")
document.text_form.u_input.value = "username";
}

</script>


This a simple HTML form to and when user click the text-box on-focus event will
call my JavaScript function.

<form name="text_form" action="#" method=post>
<input name=u_input onFocus=clear_username() value="username">
<input name=input onFocus=clear_password() value="password">
<input type=submit value=Submit>
<input type=reset>
</form>

Simple PHP Pagine

This is a simple php pagine file and You can change this according to your needs.I published this because when I need a pagine file I couldn't find.
line no 03 set the number of result rows. ex-number of product in the page
line no 04 and 05 set the start result row and end row.

0)
{
$eu=$start;
}
else
{
$eu =0;
}
?>

The query will retrieve the specific portion of data that limit by the start and end values.


$query=" SELECT * FROM student_adv limit $eu,$page_end";
$result=mysql_query($query);
echo mysql_error();


while($noticia = mysql_fetch_array($result))
{
if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}

echo "";
echo " $noticia[id]";
echo " $noticia[name]";
echo " $noticia[class]";
echo " $noticia[mark]";

echo "";
}


Retrieve all the data and count the number of rows in the result.line no 06 count the number of pages.line no 12 print the page numbers and pass the start and end row for the next page.


$query2=" SELECT * FROM student_adv ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
//setting pages
$pages_count=$nume/$limit;
print "";

for($i=0;$i<$pages_count;$i++) { $limitp=$limit; $end_limit=$i*$limit; print " ".$i.""; }

I will appreciate your comments.Let me know any errors or improvements.

jQuery Template

Simple J Query template.Used basic JQuery functions.Anyone can download this template free
















just considered JQuery functions and layout of the web site.so colors and text may be boring.

LIVE DEMO DOWNLOAD

file uploading PHP

If you need a upload a file using PHP. This is a easiest and nice way to do that. Only one line I used. You can add validation part according to your need.

Html part

<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>


The enctype attribute of the <form> tag specifies which content-type to use when submitting the form. "multipart/form-data" is used when a form requires binary data.

The type="file" attribute of the <input> tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field


one line php script

<?php
$path="E:\tharu\";
move_uploaded_file($_FILES["file"]["tmp_name"],$path.$_FILES["file"]["name"]);
?>


[file][tmp_name] - temporary storage of file .now we save this file any place we want
path = specific path
[file][name] - name of the file