Archive for June 6th, 2010


Orang bodoh sulit dapat kerja, akhirnya berbisnis…
Agar bisnisnya berhasil, tentu dia harus rekrut orang pintar.
Walhasil boss-nya orang pintar adalah orang bodoh.

Orang bodoh sering melakukan kesalahan,
maka dia rekrut orang pintar yang tidak pernah salah untuk memperbaiki yang salah.
Walhasil orang bodoh memerintahkan orang pintar untuk keperluan orang bodoh.

Orang pintar belajar untuk mendapatkan ijazah untuk selanjutnya mencari kerja.
Orang bodoh berpikir secepatnya mendapatkan uang untuk membayari proposal yang diajukan orang pintar.

Orang bodoh tidak bisa membuat teks pidato, maka dia menyuruh orang pintar untuk membuatnya.

Orang bodoh kayaknya susah untuk lulus sekolah hukum (SH).
oleh karena itu orang bodoh memerintahkan orang pintar untuk membuat undang-undangnya orang bodoh.

Orang bodoh biasanya jago cuap-cuap jual omongan,
sementara itu orang pintar percaya.
Tapi selanjutnya orang pintar menyesal karena telah mempercayai orang bodoh.
Tapi toh saat itu orang bodoh sudah ada di atas.

Orang bodoh berpikir pendek untuk memutuskan sesuatu yang dipikirkan panjang-panjang oleh orang pintar.
Walhasil orang orang pintar menjadi staf-nya orang bodoh.

Saat bisnis orang bodoh mengalami kelesuan, dia PHK orang-orang pintar yang berkerja.
Tapi orang-orang pintar DEMO.
Walhasil orang-orang pintar ‘ meratap-ratap ‘ kepada orang bodoh agar tetap diberikan pekerjaan.

Tapi saat bisnis orang bodoh maju,
orang pinter akan menghabiskan waktu untuk bekerja keras dengan hati senang,
sementara orang bodoh menghabiskan waktu untuk bersenang-senang dengan keluarganya.

Mata orang bodoh selalu mencari apa yang bisa di jadikan duit.
Mata orang pintar selalu mencari kolom lowongan perkerjaan.

Bill gate (Microsoft), Dell, Hendri (Ford), Thomas Alfa Edison, Tommy Suharto, Liem Sioe Liong (BCA group).
Adalah contoh orang-orang yang tidak pernah dapat S1), tapi kemudian menjadi kaya.
Ribuan orang-orang pintar bekerja untuk mereka.
Dan puluhan ribu jiwa keluarga orang pintar bergantung pada orang bodoh..

PERTA N YAA N :
Mendingan jadi orang pinter atau orang bodoh??
Pinteran mana antara orang pinter atau orang bodoh ???
Mana yang lebih mulia antara orang pinter atau orang bodoh??
Mana yang lebih susah, orang pinter atau orang bodoh??

KESIMPULA N :
Jangan lama-lama jadi orang pinter,
lama-lama tidak sadar bahwa dirinya telah dibodohi oleh orang bodoh.

Jadilah orang bodoh yang pinter dari pada jadi orang pinter yang bodoh.
Kata kunci nya adalah ‘ resiko ‘ dan ‘ berusaha ‘ ,
karena orang bodoh perpikir pendek maka dia bilang resikonya kecil,
selanjutnya dia berusaha agar resiko betul-betul kecil.
Orang pinter berpikir panjang maka dia bilang resikonya besar untuk
selanjutnya dia tidak akan berusaha mengambil resiko tersebut.
Dan mengabdi pada orang bodoh…

Diamanakah posisi anda saat ini…
Berhentilah meratapi keadaan anda yang sekarang…

Ini hanya sebuah Refleksi dari semua Retorika dan Dinamika kehidupan.
Semua Pilihan dan Keputusan ada ditangan anda untuk merubahnya,
Lalu perhatikan apa yang terjadi…

Stay Super…..

Salam,
Mario Teguh…

Working with Files

We can do things for files like reading, writing or appending. Before we start with files, we must open it first for reading, writing or both. PHP provides the fopen() function for doing so. fopen() requires a string that contains the file path and the mode like read (r), write (w) and append (a). Let’s see the example:

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';

	if (file_exists($file)){
		$of = fopen ($file, 'r');
		$read = fread ($of, filesize($file));
		echo $read.', panjang= ' .strlen($read);
		fclose($of);
	}
	else{
		echo 'The file is not exist';
	}
//eof

Function file_exists() is used for the existence of a file. If the file is found file_exists() return true, otherwise it returns false. Function fread() is for reading arbitrary amounts of data from a file through accept a file resource as an argument, as well as the number of bytes you want to read. Try to change line 6 above with $read = fread ($of, 10); then see the result. Assuming that all is well and you go on to work with your open file, you should remember to close it when you finish using fclose().

Checking the status of a file:
After checking that a file exists, you can find out some things that you can do with it. PHP can help you typically whether you can read, write to or execute this file.
is_readable() tells you whether you can read a file.
is_writable() tells you whether you can write to a file.
is_executable() tells you whether you can run a file, relying on either the file’s permissions or its extension depending on your platform.
All above function requires the file path and returns a Boolean value.

Getting date information about a file:
This function is used to find out when a file was last written to or accessed.
fileatime() to find out when a file was last accessed.
filemtime() to discover the modification date of a file.
filectime() to test the change time of a document.
Lets see the example:

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
	$ftime = fileatime($file);
	echo $file. ‘ was last accessed on ";
	echo date(‘D d M Y g:i A’, $ftime);

Reading lines from a file:
To read a line from an open file you can use fgets(), which requires the file resource returned from fopen() as an argument like this:

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r');
	$line = fgets ($of);
	echo $line;
	fclose($of);

Although you can read lines with fgets(), you need some way to tell when you reach the end of the file. The feof() function does this by returning true when the end of the file has been reached and false otherwise. So you have enough information to read a file line by line as shown below:

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	while (!feof($of)){
		$line = fgets($of, 10);
		echo $line;
}

Moving around a file:
Function fseek() let you decide the position manually from which the acquisition begins. fseek() enable you to change your current position within a file. It requires a file resource and an integer that represents the offset from the start of the file (in bytes) to which you want to jump. Lets see the example below:

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	$fsize = filesize($file);
	$fhalf = (int)($fsize/2);
	Echo ‘Setengah file’. $fhalf;

	fseek($of, $fhalf);
	$ branch = fread($of, ($fsize - $fhalf));
	echo $branch;

Reading characters from a file:
With use fgetc() it return only a single character from a file every time it is called. Because a character is always one byte in size, fgetc() doesn’t require a length argument.

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	while (!eof($of)){
		$char = fgetc($of);
		echo $char.’<br>’;
}

Reading entire file:
We can also read a file at one time use file_get_contents(). Lets take a look:

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of = fopen ($file, 'r') or die (‘Could not open file’);
	$files = file_get_contents($file);
	echo $files;

That code will read entire file $file and saved into $files. But be careful if the size of file is very big :d.

Writing or Appending to a file:
Writing occurs from the start of the file, any prior content is destroyed and replaced by the data you write. You use mode argument ‘w’ when you call fopen().

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of= fopen($file, ‘w’) or die (‘Could not open file’);
fwrite($of,’Hello World \n’);
fclose($of);

Appending are added the writes to the existing file. But if you have nonexistent file, the file will be created first.

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
$of= fopen($file,’a’) or die (‘Could not open file’);
fputs($of, ’and another thing \n’);
fclose($of);

Locking files:
To locking files we can use flock() which locks a file to warn other processes against writing to or reading file while the current process is working with file. I mean you don’t need your file being corrupt because other user accessing files at the time. You should call flock() directly after calling fopen() and call it again to release the lock before closing the file. If the lock is not released, you will not be able to read or write to that file.

<?
$file='D:\xampp\htdocs\exprogram\filetxt\readme.txt';
	$of = fopen($file, ‘a’) or die (‘Could not open file’);
	flock($of, LOCK_EX); // exclusive lock
		// read or write to the file
	flock($of, LOCK_UN); // release the lock
	fclose($of);

There is another constant with type shared that is LOCK_SH. This type allows other processes to read the file but prevent writing (used when reading a file).

Powered by WordPress.