150 likes | 290 Views
Skedaret. Programim ne Web Leksion 8. Perfshirja i skedareve me include(). < html> < head> <title>Si te perdorim include ()</title> </ head> < body> <? php include (" listing.php "); ?> </ body> </ html>. Perfshirja i skedareve me include(). Permbajtja e listing.php
E N D
Skedaret Programim ne Web Leksion 8 Iralda Mitro
Perfshirja i skedareve me include() <html> <head> <title>Si teperdorim include()</title> </head> <body> <?php include("listing.php"); ?> </body> </html> Iralda Mitro
Perfshirja i skedareve me include() • Permbajtja e listing.php I have been included!! Iralda Mitro
Perdorimii include() per teekzekutuar PHP ne njeskedartjeter <html> <head> <title> Perdorimii include() per teekzekutuar PHP ne njeskedartjeter </title> </head> <body> <?php include("listing2.php"); ?> </body> </html> Iralda Mitro
Nje skedar include qe mban kod PHP • listing2.php <?php print "I have been included!"; print "But now I can add up... 4 + 4 = ".(4 + 4); ?> • I have been included!! But now I can add up... 4 + 4 = 8 Iralda Mitro
Kthimi i nje vlere nga nje dokument i perfshire <html> <head> <title>Using include() to execute PHP and assign the return value</title> </head> <body> <?php $addResult = include("listing3.php"); print "The include file returned $addResult"; ?> </body> </html> Iralda Mitro
Kthimi i nje vlere nga nje dokument i perfshire • An Include File That Returns a Value <?php $retval = (4 + 4); return $retval; ?> This HTML will never be displayed because it comes after a return statement! • The include file returned 8 Iralda Mitro
Perdorimii include() brendastrukturavetekontrollit <html> <head> <title>Using include() within a loop</title> </head> <body> <?php for ( $x = 1; $x<=3; $x++ ) { $incfile = "incfile$x".".txt"; print "Attempting include $incfile<br>"; include( "$incfile" ); print "<p>"; } ?> </body> </html> Iralda Mitro
Testimiiekzistences se skedareve if (file_exists("test.txt")) { print "The file exists!"; } Iralda Mitro
Testimi i skedareve • Skedarapodirektori? if (is_file("test.txt")) { print "test.txt is a file!"; } if (is_dir("/tmp")) { print "/tmp is a directory"; } Iralda Mitro
TestimiStatusitteskedareve if (is_readable("test.txt")) { print "test.txt is readable"; } if (is_writable("test.txt")) { print "test.txt is writable"; } if (is_executable("test.txt")) { print "test.txt is executable"; } Iralda Mitro
Testimimadhesise se skedareve print "The size of test.txt is.. "; print filesize("test.txt"); Iralda Mitro
Shembull: Testimiiskedareve 1: <html> 2: <head> 3: <title>Listing 10.8 A function to output the results of 4: multiple file tests</title> 5: </head> 6: <body> 7: <?php 8: $file = "test.txt"; 9: outputFileTestInfo($file); 11: function outputFileTestInfo($f) { 12: if (!file_exists($f)) { 13: print "$f does not exist<BR>"; 14: return; 15: } 16: print "$f is ".(is_file($f)?"":"not ")."a file<br>"; 17: print "$f is ".(is_dir($f)?"":"not ")."a directory<br>"; 18: print "$f is ".(is_readable($f)?"":"not ")."readable<br>"; 19: print "$f is ".(is_writable($f)?"":"not ")."writable<br>"; 20: print "$f is ".(is_executable($f)?"":"not ")."executable<br>"; 21: print "$f is ".(filesize($f))." bytes<br>"; 22: print "$f was accessed on ".date("D d M Y g:i A",fileatime($f))."<br>"; 23: print "$f was modified on ".date("D d M Y g:i A",filemtime($f))."<br>"; 24: print "$f was changed on ".date("D d M Y g:i A",filectime($f))."<br>"; 25: } 27: ?> 28: </body> 29: </html> Iralda Mitro
Hapja e skedaritper lexim, shkrimdheshtim • $fp = fopen("test.txt", 'r'); • $fp = fopen("test.txt", 'w'); • $fp = fopen("test.txt", ‘a'); Iralda Mitro
Mbyllja e skedarit • $fp = fopen("test.txt", 'r'); • fclose($fp); Iralda Mitro