Pages

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

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


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.

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