Difference between revisions of "CSC220 uploadFile3.htm"
(→FileUpload3.php) |
(→FileUpload3.php) |
||
Line 69: | Line 69: | ||
$text = file_get_contents( $tmp_name ); | $text = file_get_contents( $tmp_name ); | ||
− | printf( "<br /> | + | printf( "<br /><pre>%s</pre><br />\n\n", $text ); |
} | } | ||
Latest revision as of 10:57, 8 November 2010
--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</pre><br />\n\n", $text );
}
//----------------------------------------------------------------
// M A I N
//----------------------------------------------------------------
printHtmlHead();
//displayTable( "FILES", $_FILES );
displayFile();
printHtmlTail();
?>