All pastes #185774 Raw Edit

Mine

public php v1 · immutable
#185774 ·published 2006-09-29 09:12 UTC
rendered paste body
<?php############################# code im trying to add############################$target_path = "uploads/";$target_path = $target_path . basename( $_FILES['excelFile']['tmp_name']); if(move_uploaded_file($_FILES['excelFile']['tmp_name'], $target_path)) {    echo "The file ".  basename( $_FILES['excelFile']['name']).     " has been uploaded";} else{    echo "There was an error uploading the file, please try again!";}############################## end additional code#############################  // Check to see if the form was submitted.  if (!isset($_POST['submit']))    {      // Show the upload form if not.      include_once 'excelUpload.tpl';    }    // If we get here the form was submitted.  else    {      // Load the configuration file and the excel reader.      $conf = parse_ini_file('config.ini');      require_once 'excel/reader.php';            // Check to see that the excel file was uploaded.      if (!is_uploaded_file($_FILES['excelFile']['tmp_name']))        {          $reason = "Unable to upload file!";          include_once 'uploadFailed.tpl';        }            // No error, proceed with importing the data.      else        {z          // Get an instance of the excel file reader.          $data = new Spreadsheet_Excel_Reader();                    // Set output Encoding.          $data->setOutputEncoding('CP1251');                    // Read in the excel file.          $data->read($_FILES['excelFile']['tmp_name']);                    // Create a connection to the database.          $link = mysql_connect($conf['dbhost'], $conf['dbuser'], $conf['dbpass']);          mysql_select_db($conf['dbname']);          // Delete any listings already in there (this will prevent multiple instances!)          $sql = 'DROP TABLE IF EXISTS `listings`';                    $sql2 = 'CREATE TABLE `listings` ( 				   `id` int(11) NOT NULL auto_increment, 				   `address` varchar(255) collate latin1_general_ci NOT NULL, 				   `apt` varchar(5) collate latin1_general_ci NOT NULL, 				   `bedrooms` tinyint(1) NOT NULL, 				   `bath` tinyint(1) NOT NULL, 				   `city` varchar(255) collate latin1_general_ci NOT NULL, 				   `furnished` varchar(1) collate latin1_general_ci NOT NULL, 				   `disposal` varchar(1) collate latin1_general_ci NOT NULL, 				   `ac` varchar(1) collate latin1_general_ci NOT NULL, 				   `dishw` varchar(1) collate latin1_general_ci NOT NULL, 				   `balcony` varchar(1) collate latin1_general_ci NOT NULL, 				   `patio` varchar(1) collate latin1_general_ci NOT NULL, 				   `parking` varchar(1) collate latin1_general_ci NOT NULL, 				   `available` varchar(1) collate latin1_general_ci NOT NULL, 				   `path` varchar(255) collate latin1_general_ci NOT NULL,				   PRIMARY KEY  (`id`) 				 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1112 ';          mysql_query($sql);          mysql_query($sql2);          echo 'Creating table: \'listings\'....';                    // Loop through the excel data to build the sql queries used to insert the data          // into the database.          for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++)            {              // Create a container for the data.              $listingData = array();                            // Loop through the excel data.              for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++)                {                  // Store the value of the current cell.                  $temp = $data->sheets[0]['cells'][$i][$j];                  if (is_null($temp))                    {                      // If the current cell is null set it to 'n'                      $temp = 'n';                    }                                    // Store the value in the container.                  $listingData[] = $temp;                }                            // Create a sql statement to insert the current excel row.              $sql = "insert into listings (address, apt, bedrooms, bath, city,                                          furnished, disposal, ac, dishw, balcony,                                          patio, parking, available, path)                    values('$listingData[0]', '$listingData[1]', '$listingData[2]',                           '$listingData[3]', '$listingData[4]', '$listingData[5]',                          '$listingData[6]', '$listingData[7]', '$listingData[8]',                           '$listingData[9]', '$listingData[10]', '$listingData[11]', '$listingData[12]', '$listingData[13]');";                            // Attempt to insert the data.              $result = mysql_query($sql);                            // If there was an error display it.              if (!$result)                {                  $reason = mysql_error() . "<br /><br />" . $sql;                  include_once 'uploadFailed.tpl';                  exit;                }            }                    // Show a successful upload.          include_once 'uploadSuccessful.tpl';        }    }?>