CSC220 uploadFile3.htm
--D. Thiebaut 15:08, 8 November 2010 (UTC)
Contents
FileUpload3.htm
(This is the same as uploadFile1.htm.)
<html>
<body>
<form enctype ="multipart/form-data"
action ="uploadFile3.php"
method ="POST">
File name: <input name="uploaded" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>
FileUpload3.php
- This php program will read the contents of the temporary file and display it on the browser.
<?php
//----------------------------------------------------------------
function printHtmlHead() {
?>
<html>
<body>
<?php
}
//----------------------------------------------------------------
function printHtmlTail() {
?>
</body>
</html>
<?php
}
//----------------------------------------------------------------
function displayTable( $caption, $table ) {
printf( "<h3>%s</h3>\n", $caption );
echo "<pre>\n";
print_r( $table );
echo "</pre>\n";
}
//----------------------------------------------------------------
function displayFile( ) {
$originalName = $_FILES['uploaded']['name'];
$tmp_name = $_FILES['uploaded']['tmp_name'];
$destination = "uploads/" . $originalName;
print "<h3> $originalName </h3> <br />";
//print "tmp_name = $tmp_name <br />";
//print "destination = $destination <br />";
$text = file_get_contents( $tmp_name );
printf( "<br /><pre>%s
\n\n", $text );
}
//----------------------------------------------------------------
// M A I N
//----------------------------------------------------------------
printHtmlHead();
//displayTable( "FILES", $_FILES );
displayFile();
printHtmlTail();
?>
</pre>