CSC220 uploadFile3.htm

From dftwiki3
Revision as of 10:55, 8 November 2010 by Thiebaut (talk | contribs) (Created page with '--D. Thiebaut 15:08, 8 November 2010 (UTC) ---- __TOC__ <br /> =FileUpload3.htm= (This is the same as uploadFile1.htm.) <code><pre>…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut 15:08, 8 November 2010 (UTC)



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 "
\n";

}

//---------------------------------------------------------------- function displayFile( ) {

 $originalName = $_FILES['uploaded']['name'];
 $tmp_name     = $_FILES['uploaded']['tmp_name'];
 $destination  = "uploads/" . $originalName;
print "

$originalName


";
 //print "tmp_name = $tmp_name 
"; //print "destination = $destination
";
 $text = file_get_contents( $tmp_name );
printf( "
%s

\n\n", $text );

}

//---------------------------------------------------------------- // M A I N //---------------------------------------------------------------- printHtmlHead(); //displayTable( "FILES", $_FILES ); displayFile(); printHtmlTail();

?>



</pre>