web view2. write a php code to complete programmer. copying, rename, write and append file....

11
2. Write a php code to complete programmer. Copying, Rename, Write and Append file. a. copyfile.php PHP Code: <?php $soure = 'C:\xampp\php\install.txt'; $dest = 'C:\Users\amanoren\Desktop\install.php'; if (!copy($soure, $dest)) { echo "failed to copy $file...n"; } else { $msg= "Done Copy File and look at you file"; } ?> <html><head><title>Copying files</title></head> <body> <?php echo ($msg);?> </body></html>

Upload: phamminh

Post on 31-Jan-2018

231 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

2. Write a php code to complete programmer. Copying, Rename, Write and Append file.

a. copyfile.php

PHP Code:

<?php $soure = 'C:\xampp\php\install.txt'; $dest = 'C:\Users\amanoren\Desktop\install.php';

if (!copy($soure, $dest)) { echo "failed to copy $file...n"; }

else {

$msg= "Done Copy File and look at you file";}?><html><head><title>Copying files</title></head><body>

<?php echo ($msg);?></body></html>

Page 2: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

In file C:\xampp\php\install.txt

AT MY DESKTOP

Before

Page 3: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

Run The Copy Code With Xampp

AT MY DESKTOP

After

Page 4: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

b. renamefile.php

PHP Code:

<?php

$old = 'C:\Users\amanoren\Desktop\install.php';$new = 'C:\Users\amanoren\Desktop\install123.php';

if(!rename($old, $new)){

echo "Unable to rename $old to $new...n";}else {

$msg= "Done Rename File and look at you Desktop";}?><html><head><title>Rename files</title></head><body>

<?php echo ($msg);?></body></html>

AT MY DESKTOP

Before

Page 5: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

Run The Copy Code With Xampp

AT MY DESKTOP

After

Page 6: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

c. writingfile.php

PHP Code :

<?php $filename = 'C:\Users\amanoren\Desktop\newFile.txt';$towrite = "Nama Saya Abdur Rahman Bin Nasaruddin";

$openedfile = fopen($filename, "w");fwrite($openedfile, $towrite);$whatsinthefile = file_get_contents($filename);echo ($whatsinthefile);?><html><head><title>Copying files</title></head><body>

<?php if(file_exists($filename)){

$file_length=filesize($filename);$msg= "<br>File created at $filename<br>";$msg.="containing $file_length bytes";echo $msg;

}else

echo "unble to create file";?>

</body></html>

AT MY DESKTOP

Before

Page 7: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

Run The Copy Code With Xampp

AT MY DESKTOP

After

Page 8: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

d. appendfile.php

PHP Code

<?php $filename = 'C:\Users\amanoren\Desktop\newFile.txt';$string = file_get_contents($filename);$string .=" Jabatan Teknologi Maklumat dan Komunikasi, Politeknik Ungku Omar, Jalan Raja Musa Mahadi, 31400, Ipoh";file_put_contents($filename, $string);$whatsinthefile = file_get_contents($filename);echo ($whatsinthefile);?><html><head><title>Append files</title></head><body><?php

if(file_exists($filename)){

$file_length=filesize($filename);$msg= "<br>File created at $filename<br>";$msg.="containing $file_length bytes";echo $msg;

}else

echo "unble to create file";?>

</body></html>

Run The Copy Code With Xampp

Page 9: Web view2. Write a php code to complete programmer. Copying, Rename, Write and Append file. copyfile.php. PHP Code:

IN FILE newFile.txt

Before

After