Difference between revisions of "CSC220 uploadFile3.htm"

From dftwiki3
Jump to: navigation, search
(Created page with '--D. Thiebaut 15:08, 8 November 2010 (UTC) ---- __TOC__ <br /> =FileUpload3.htm= (This is the same as uploadFile1.htm.) <code><pre>…')
 
(FileUpload3.php)
 
(One intermediate revision by the same user not shown)
Line 54: Line 54:
 
function displayTable( $caption, $table ) {
 
function displayTable( $caption, $table ) {
 
   printf( "<h3>%s</h3>\n", $caption );
 
   printf( "<h3>%s</h3>\n", $caption );
   echo "<pre>\n";
+
   echo "&lt;pre&gt;\n";
 
   print_r( $table );
 
   print_r( $table );
   echo "</pre>\n";
+
   echo "&lt;/pre&gt;\n";
 
}
 
}
  
Line 69: Line 69:
  
 
   $text = file_get_contents( $tmp_name );
 
   $text = file_get_contents( $tmp_name );
   printf( "<br /><pre>%s</pre><br />\n\n", $text );
+
   printf( "<br />&lt;pre&gt;%s&lt;/pre&gt;<br />\n\n", $text );
 
}
 
}
  

Latest revision as of 10:57, 8 November 2010

--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 "</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();

?>