How to Resize an Image Using PHP
Source:http://www.4wordsystems.com/php_image_resize.php
Part I: The HTML Form
<form action="upload.php" method="post" enctype="multipart/form-data" >
<input type="file" name="uploadfile"/>
<input type="submit"/>
</form>
Part II: Getting at the file, resizing the image, and saving to the server. (upload.php)
<?php
// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=600;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "images/". $_FILES['uploadfile']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
// has completed.
?>
Add comment May 5, 2009
Get Email From a String in PHP
<?php
/*
Snippet Name: Get Emails from Strings
Author : Hermawan Haryanto
Email : hermawan@codewalkers.com
Homepage: http://hermawan.com
Blog : http://hermawan.codewalkers.com
*/
function get_emails ($str)
{
$emails = array();
preg_match_all("/\b\w+\@\w+[\.\w+]+\b/", $str, $output);
foreach($output[0] as $email) array_push ($emails, strtolower($email));
if (count ($emails) >= 1) return $emails;
else return false;
}
# Here is how to use it.
# Sample string containing email addresses;
$str = "test test@test.com ha ha heHe@test.com bla bla bla@test.com";
# Get the emails on arrays;
$emails = get_emails ($str);
# Print that arrays;
print_r ($emails);
?>
Add comment March 26, 2009
There Are Only 10 Types of People In This World
Those who can understand binary, and those who cannot.
Source: somewhere in the internet…
Add comment March 23, 2009
Speed Up Torrents With Low Or Zero Seeders
source: http://filesharefreak.com/tutorials/how-to-speed-up-torrents-with-low-seeders/
Simple. Just copy/paste this list of public trackers into your torrent’s tracker list.
NOTE: Do not attempt this trick with private torrents – it’ll only get you banned from the tracker. Use this tip with torrents you find at mininova, thepiratebay, etc.
http://tracker2.istole.it:60500/announce
http://inferno.demonoid.com:3407/announce
http://vip.tracker.thepiratebay.org/announce
http://track.sextorrent.to:2710/announce
http://tracker.deluxebits.to:3552/announce
http://denis.stalker.h3q.com:6969/announce
http://tracker.thepiratebay.org/announce
http://tracker.torrentbox.com:2710/announce
http://tracker.hexagon.cc:2710/announce
http://tracker.torrent.to:2710/announce
http://axxo.sladinki007.net:6500/announce
http://220.162.244.175:53880/announce
http://tpb.tracker.prq.to/announce
http://open.tracker.thepiratebay.org/announce
http://eztv.sladinki007.net:60500/announce
http://tv.tracker.prq.to/announce
http://218.145.160.136:8080/announce
http://tracker.prq.to/announce
http://tracker.torrenty.org:6969/announce
http://tpb.tracker.thepiratebay.org/announce
http://t.ppnow.net:2710/announce
http://www.torrentvideos.com:6969/announce
http://tracker.bitebbs.com:6969/announce
http://www.torrent-downloads.to:2710/announce
http://eztv.sladinki007.eu:60500/announce
http://www.ipmart-forum.com:2710/announce
http://tracker.ydy.com:83/announce
http://bt1.the9.com:6969/announce
http://tracker.sladinki007.net:6500/announce
http://tracker.ydy.com:102/announce
http://tracker.paradise-tracker.com:12000/announce
http://moviesb4time.biz/announce.php
http://tracker.deadfrog.us:42426/announce
http://mpggalaxy.mine.nu:6969/announce
http://www.sumotracker.org/announce
If you don’t know how to do it, click the source I mentioned above for instructions.
Add comment March 13, 2009
A PHP Class To Manage Processes In Linux
I found this helpful snippet of code on PHP.net when I was searching for a way to start and stop processes initiated by exec().
/* An easy way to keep in track of external processes.
* Ever wanted to execute a process in php, but you still wanted to have somewhat controll of the process ? Well.. This is a way of doing it.
* @compability: Linux only. (Windows does not work).
* @author: Peec
*/
class Process{
private $pid;
private $command;
public function __construct($cl=false){
if ($cl != false){
$this->command = $cl;
$this->runCom();
}
}
private function runCom(){
$command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!';
exec($command ,$op);
$this->pid = (int)$op[0];
}
public function setPid($pid){
$this->pid = $pid;
}
public function getPid(){
return $this->pid;
}
public function status(){
$command = 'ps -p '.$this->pid;
exec($command,$op);
if (!isset($op[1]))return false;
else return true;
}
public function start(){
if ($this->command != '')$this->runCom();
else return true;
}
public function stop(){
$command = 'kill '.$this->pid;
exec($command);
if ($this->status() == false)return true;
else return false;
}
}
1 comment March 7, 2009
Installing MRTG on Linux
Website: http://oss.oetiker.ch/mrtg/
Full installation documentation at http://oss.oetiker.ch/mrtg/doc/mrtg-unix-guide.en.html
PREREQUISITES:
These are other software that are needed for MRTG to be installed correctly
- GCC compiler
- Perl
- Gd library
- Libpng library
- Zlib (needed by libpng)
- SNMP (Simple Network Management Protocol)
LIBRARY COMPILATION:
First let’s create a directory for the compilation. Note that this may already exist on your system. No problem, just use it.
mkdir -p /usr/local/src cd /usr/local/src
If you do not have zlib installed:
wget http://www.gzip.org/zlib/zlib-1.1.4.tar.gz gunzip -c zlib-*.tar.gz | tar xf - rm zlib-*.tar.gz mv zlib-* zlib cd zlib ./configure make cd ..
If you don’t have libpng installed
wget http://public.planetmirror.com/pub/sourceforge/l/li/libpng/libpng-1.0.15.tar.gz gunzip -c libpng-*.tar.gz |tar xf - rm libpng-*.tar.gz mv libpng-* libpng cd libpng* make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib rm *.so.* *.so cd ..
And now you can compile gd
The \ characters at the end of the following lines mean that all the following material should actually be written on a single line.
For versions starting around 2.0.11, try:
wget http://www.boutell.com/gd/http/gd-2.0.11.tar.gz gunzip -c gd-2.0.11.tar.gz |tar xf - mv gd-2.0.11 gd cd gd env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" / ./configure --disable-shared --without-freetype --without-jpeg make cp .libs/* .
MRTG Installation
mkdir -p /usr/local/src/mrtg
cd /usr/local/src/mrtg
wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.15.2.tar.gz
wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.15.2.tar.gz
cd mrtg-2.15.2
./configure –prefix=/usr/local/mrtg-2
make && make install
That’s it. MRTG is now installed in the prefixed directory: /usr/local/mrtg-2
Net-SNMP Installation
mkdir -p /usr/local/src/snmp
cd /usr/local/src/snmp
wget http://nchc.dl.sourceforge.net/sourceforge/net-snmp/net-snmp-5.2.4.tar.gz
tar zxvf net-snmp-5.2.4.tar.gz
Configure your SNMP package
cd /usr/local/src/snmp/net-snmp-5.2.4
./configure –prefix=/usr/local/net-snmp
Note: You will be asked some questions regarding setting up SNMP such as the following:
(a.) Default version of SNMP to use: Choose 2
(b.) System Contact Information: type in your email address
(c.) System Location: Type in the location of this box (City-Country)
(d.) Location to write log file: /var/log/snmpd.log
(e.) Location to write persistent information: /var/net-snmp
Compile and install SNMP
make && make install
Configuration of snmpd.conf
Create the etc directory to hold your snmpd.conf file.
mkdir -p /usr/local/net-snmp/etc
Create the snmpd.conf
vi /usr/local/net-snmp/etc/snmpd.conf
##Copy and paste the following##
#############Start of snmpd.conf###########################
#
# snmpd.conf
#
# – created by Tek Limbu on 05-Dec-2007
#
#######################################################
# SECTION: System Information Setup
#
# This section defines some of the information reported in
# the “system” mib group in the mibII tree.
# syslocation: The [typically physical] location of the system.
# Note that setting this value here means that when trying to
# perform an snmp SET operation to the sysLocation.0 variable will make
# the agent return the “notWritable” error code. IE, including
# this token in the snmpd.conf file will disable write access to
# the variable.
# arguments: location_string
syslocation Sweden
# syscontact: The contact information for the administrator
# Note that setting this value here means that when trying to
# perform an snmp SET operation to the sysContact.0 variable will make
# the agent return the “notWritable” error code. IE, including
# this token in the snmpd.conf file will disable write access to
# the variable.
# arguments: contact_string
syscontact mikeyhacky@gmail.com
#####################################################
# SECTION: Access Control Setup
#
# This section defines who is allowed to talk to your running
# snmp agent.
# rocommunity: a SNMPv1/SNMPv2c read-only access community name
# arguments: community [default|hostname|network/bits] [oid]
rocommunity MyPass333
#Disk size in Megabytes (MB).
disk /usr
disk /var
#################End of snmpd.conf########################
The most important data in any SNMP configuration is the community string which can be compared to a password. In the above snmpd.conf file, the rocommunity stands for read-only community string which has the value “MyPass333″. As with passwords, this has to be kept as as secret!
Run the SNMP daemon using the above snmpd.conf file.
/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/etc/snmpd.conf
Test to see if SNMP is working and functioning properly.
/usr/local/net-snmp/bin/snmpwalk -v2c -c MyPass333 localhost system
You should see something like the following:
###############################################
SNMPv2-MIB::sysDescr.0 = STRING: Linux gw-npj-sp 2.6.18-4-686 #1 SMP Mon Mar 26 17:17:36 UTC 2007 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
SNMPv2-MIB::sysUpTime.0 = Timeticks: (168913) 0:28:09.13
SNMPv2-MIB::sysContact.0 = STRING: tekbdrlimbu@hotmail.com
SNMPv2-MIB::sysName.0 = STRING: linux-box-hostname
SNMPv2-MIB::sysLocation.0 = STRING: Kathmandu-Nepal
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00
##############################################
Creating your 1st MRTG graph using SNMP (assuming that DocumentRoot is located at /var/www/html)
mkdir -p /usr/local/mrtg-2/etc
mkdir -p var/www/html/mrtg/traffic [var/www/html/ is the DocumentRoot of the server, change this if necessary]
/usr/local/mrtg-2/bin/cfgmaker –output=/usr/local/mrtg-2/etc/mrtg.cfg /
–global “workdir: /var/www/html/mrtg/traffic” /
-ifref=ip –global ‘options[_]: growright,bits’ MyPass333@localhost
[localhost should be the URL or IP address of the server]
Finally run the mrtg tool to generate the graphs.
env LANG=C /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/etc/mrtg.cfg
Generate your index.html file using the tool called indexmaker which comes with the MRTG package.
/usr/local/mrtg-2/bin/indexmaker –title=”Traffic Status” /usr/local/mrtg-2/etc/mrtg.cfg /
> var/www/html/mrtg/traffic/index.html
We need to setup an entry in the cron table to update the MRTG graphs every 5 minutes. On a Linux or FreeBSD machine, you can do it the following way:
vi /etc/crontab
##### Copy and paste the following #####
*/5 * * * * root env LANG=C /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/etc/mrtg.cfg > /dev/null 2>&1
There you have it. Your graphs will update every 5 minutes indicating the traffic flow in your eth0 network interface.
Add comment February 27, 2009




