Programim ne Web

Download Report

Transcript Programim ne Web

Skedaret
Programim ne Web
Leksion 8
Iralda Mitro
1
Perfshirja i skedareve me include()
<html>
<head>
<title>Si te perdorim include()</title>
</head>
<body>
<?php
include("listing.php");
?>
</body>
</html>
Iralda Mitro
2
Perfshirja i skedareve me include()
• Permbajtja e listing.php
I have been included!!
Iralda Mitro
3
Perdorimi i include() per te ekzekutuar PHP
ne nje skedar tjeter
<html>
<head>
<title>
Perdorimi i include() per te ekzekutuar PHP
ne nje skedar tjeter
</title>
</head>
<body>
<?php
include("listing2.php");
?>
</body>
</html>
Iralda Mitro
4
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
5
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
6
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
7
Perdorimi i include() brenda strukturave te
kontrollit
<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
8
Testimi i ekzistences se skedareve
if (file_exists("test.txt")) {
print "The file exists!";
}
Iralda Mitro
9
Testimi i skedareve
• Skedar apo direktori?
if (is_file("test.txt")) {
print "test.txt is a file!";
}
if (is_dir("/tmp")) {
print "/tmp is a directory";
}
Iralda Mitro
10
Testimi Statusit te skedareve
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
11
Testimi madhesise se skedareve
print "The size of test.txt is.. ";
print filesize("test.txt");
Iralda Mitro
12
Shembull: Testimi i skedareve
1:
2:
3:
4:
5:
6:
7:
8:
9:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
27:
28:
29:
<html>
<head>
<title>Listing 10.8 A function to output the results of
multiple file tests</title>
</head>
<body>
<?php
$file = "test.txt";
outputFileTestInfo($file);
function outputFileTestInfo($f) {
if (!file_exists($f)) {
print "$f does not exist<BR>";
return;
}
print "$f is ".(is_file($f)?"":"not ")."a file<br>";
print "$f is ".(is_dir($f)?"":"not ")."a directory<br>";
print "$f is ".(is_readable($f)?"":"not ")."readable<br>";
print "$f is ".(is_writable($f)?"":"not ")."writable<br>";
print "$f is ".(is_executable($f)?"":"not ")."executable<br>";
print "$f is ".(filesize($f))." bytes<br>";
print "$f was accessed on ".date("D d M Y g:i A",fileatime($f))."<br>";
print "$f was modified on ".date("D d M Y g:i A",filemtime($f))."<br>";
print "$f was changed on ".date("D d M Y g:i A",filectime($f))."<br>";
}
?>
</body>
</html>
Iralda Mitro
13
Hapja e skedarit per lexim, shkrim dhe shtim
• $fp = fopen("test.txt", 'r');
• $fp = fopen("test.txt", 'w');
• $fp = fopen("test.txt", ‘a');
Iralda Mitro
14
Mbyllja e skedarit
• $fp = fopen("test.txt", 'r');
• fclose($fp);
Iralda Mitro
15