CSC220 downloadFile0 php

From dftwiki3
Jump to: navigation, search

--D. Thiebaut 14:40, 1 November 2010 (UTC)


<?php
// downloadFile0.php
// D. Thiebaut

include 'accessinfo.php';
$database = "220a_example7";

function displayArray( $table ) {
  print "<pre>";
  print_r( $table);
  print "</pre>";
}

//--- connect to mysql server ---
$link = mysql_connect( $hostName, $userName, $password );
if ( ! $link ) 
  die( "Could not connect to server: " . $mysql_error() );
//print "Connected to " . $hostName . "\n<br />";

//--- select database ---
$db = mysql_select_db( $database, $link );
if ( ! $db ) 
  die( "Could not connect to database " . $database . ": "
       . mysql_error() );

//print "Database ". $database . " selected\n<br />";

//--- get first image and display it ----
$query = "SELECT `Name`, `Size`, `Type`, `Contents` FROM `images` "
          . " LIMIT 1 ";
$result = mysql_query( $query, $link );
  
if ( $result )  {
  $row = mysql_fetch_array( $result, MYSQL_ASSOC );
  $contents = stripslashes( $row[ 'Contents' ] );
  echo $contents;
}
//else 
  //printf( "Error, cannot display image. %s<br />" , mysql_error() );

//--- close database ---
mysql_close( $link );
?>