Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
// or include URL;
// or require URL;
Example:
echo "first<br>";
include("second.php");
echo "first<br>";
If URL doesnt exist the require function results fatal error.
FILE MANIPULATION
Create a file
Append to a file
Rename a file
Delete a file
Description
'r'
Open for reading only; place the file pointer at the beginning of the file.
'r+'
Open for reading and writing; place the file pointer at the beginning of the file.
'w'
Open for writing only; place the file pointer at the beginning of the file and truncate the file to
zero length. If the file does not exist, attempt to create it.
'w+'
Open for reading and writing; place the file pointer at the beginning of the file and truncate
the file to zero length. If the file does not exist, attempt to create it.
'a'
Open for writing only; place the file pointer at the end of the file. If the file does not exist,
attempt to create it.
'a+'
Open for reading and writing; place the file pointer at the end of the file. If the file does not
exist, attempt to create it.
'x'
Create and open for writing only; place the file pointer at the beginning of the file. If the file
already exists, the fopen() call will fail by returning FALSE and generating an error of
level E_WARNING. If the file does not exist, attempt to create it.
'x+'
Create and open for reading and writing; place the file pointer at the beginning of the file. If
the file already exists, the fopen() call will fail by returning FALSE and generating an
error of level E_WARNING. If the file does not exist, attempt to create it.
-> <
UPLOAD FILE(S)
form.php
<html> <body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> <br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not specified).
upload_tmp_dir = "c:\TEMP\"
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
upload_file.php
<?php
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br />";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
$_FILES
RESTRICTIONS ON UPLOAD
<?php
if (
(($_FILES["file"]["type"] == "image/gif") ||
($_FILES["file"]["type"] == "image/jpeg") ||
($_FILES["file"]["type"] == "image/pjpeg"))
&&
($_FILES["file"]["size"] < 20000)) {
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br />";
} else {
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
} else {
echo "Invalid file";
}
?>
SAVING
THE
UPLOADED
FILE
<?php
if (
} else {
echo "Invalid file";
}
?>