Thứ Bảy, 19 tháng 1, 2008

Copy
copy($file, $newfile);
Lay file size dang byte
filesize($filename);
Tat thong bao loi cua php
error_reporting(0);
Kiem tra file info.php co ton tai khong gia tri tra ve la tru hay false
file_exists('info.php');
Kiem tra ket thuc file chua gia tri tra ve la tru hay false
feof($file);
Doc file theo char
fgetc($file);
Doc file theo string hay theo tung dong
fgets($file);
Mo file welcome.txt de doc
fopen("welcome.txt","r");
Tra ve ten file bao gom phan mo rong hay chi ten file
$path = "index.php";
$file = basename($path); // $file la "index.php"
$file = basename($path, ".php"); // $file la "index"
$f = "path/to/file.xml#xpointer(/Texture)";
$file =basename($f, ".xml#xpointer(/Texture)") //$file la file
Tra ve thu muc cao hon mot cap
$path = "/etc/passwd";
$file = dirname($path); // $file la "/etc"
Tra ve phan mo rong cua file
$path_parts = pathinfo('/abc/dirname.jpg');
$extension = $path_parts['extension']; //$extension la jpg
Go bo thiet lap cho bien
$foo = 'bar';
unset($foo);
Lay thong tin ve dia cung
disk_free_space("C:");
disk_total_space("C:");
Ham chuyen byte sang mega giga ....
function HumanSize($Bytes)
{
$Type=array("", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta");
$Index=0;
while($Bytes>=1024)
{
$Bytes/=1024;
$Index++;
}
return("".$Bytes." ".$Type[$Index]."bytes");
}
phpftp

<?php
// set up basic connection
$ftp_server = "localhost";
$ftp_user_name = "dao";
$ftp_user_pass = "123";
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name<br>";
}

// try to chmod $file to 644
$file = "abc";
if (ftp_chmod($conn_id, 0644, $file) !== false) {
echo "$file chmoded successfully to 644n";
} else {
echo "could not chmod $filen";
}

// try to delete $file
$file = "abc.zip";
if (ftp_delete($conn_id, $file)) {
echo "$file deleted successfuln";
} else {
echo "could not delete $filen";
}


//change dir
echo " Current directory: " . ftp_pwd($conn_id)."<br>";
if (ftp_chdir($conn_id, "file")) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "<br>";
} else {
echo "Couldn't change directoryn";
}


//lay noi dung thu muc va in ra
$contents = ftp_nlist($conn_id, ".");
var_dump($contents);

//liet ke theo thu tu abc
$ftp_nlist = ftp_nlist($conn_id, ".");

sort($ftp_nlist);

foreach ($ftp_nlist as $v) {

//xac dinh thu muc va in ra
if (ftp_size($conn_id, $v) == -1) {
echo " " . $v . " <br />n";
}
}
foreach ($ftp_nlist as $v) {

//xac dinh file va in ra
if (!(ftp_size($conn_id, $v) == -1)) {
echo "" . $v . "<br />n";
}
}

// return to the parent directory
if (ftp_cdup($conn_id)) {
echo "cdup successful<br>";
} else {
echo "cdup not successfuln";
}
echo " Current directory: " . ftp_pwd($conn_id)."<br>";

//khai bao upload
$source_file = "cmdasp.zip";
$destination_file = "abc.zip";
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file<br>";
}

//download file
// duong dan file o xa va cuc bo
$remote_file = 'abc.zip';
$local_file = '007.zip';
// open some file to write to
$handle = fopen($local_file, 'w');
// download file $remote_file va save thanh $handle
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {
echo "Successfully written to $local_file<br>";
} else {
echo "There was a problem while downloading $remote_file to $local_filen";
}

// tao thu muc $dir
$dir = 'vvv';
if (ftp_mkdir($conn_id, $dir)) {
echo "Successfully created $dir<br>";
} else {
echo "There was a problem while creating $dirn";
}

$dir = 'vvv/bbb';
if (ftp_mkdir($conn_id, $dir)) {
echo "Successfully created $dir<br>";
} else {
echo "There was a problem while creating $dirn";
}

//doi ten $old_file to $new_file
$old_file = 'vvv/bbb';
$new_file = 'vvv/ccc';
if (ftp_rename($conn_id, $old_file, $new_file)) {
echo "Successfully renamed $old_file to $new_filen";
} else {
echo "There was a problem while renaming $old_file to $new_filen";
}

// close the FTP stream
ftp_close($conn_id);
?>

0 Nhận xét:

Đăng nhận xét

Đăng ký Đăng Nhận xét [Atom]

<< Trang chủ