• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

PHP form upload script

I am working on an add page for reports on our website. We have a form which adds the details into our database. It also adds an image to the website and then adds the name to the database entry. We are using a ready made script which comes as an addon to dreamweaver called interakt but it just makes the code plain ugly and inefficient.

Can anyone either recommend code or provide a link to somewhere with another usable solution? It doesn't need to be anything flash it just needs to upload a logo and then place the name of the logo and then add details of the report (incl logo) to the mysql db in one form so that our view script can pull it all down (the easy part).

For anyone interested here is what we currently have for adding. I have left out the form itself. Man I hate dreamweaver
require_once('/home/site/public_html/Connections/conn_database.php'); 
require_once('/home/site/public_html/cms/current.php');
require_once('/home/site/public_html/includes/common/KT_common.php');
require_once('/home/site/public_html/includes/tng/tNG.inc.php');
 
// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger
 
//start Trigger_ImageUpload trigger
//remove this line if you want to edit the code by hand 
function Trigger_ImageUpload(&$tNG) {
  $uploadObj = new tNG_ImageUpload($tNG);
  $uploadObj->setFormFieldName("logo");
  $uploadObj->setDbFieldName("logo");
  $uploadObj->setFolder("/home/site/public_html/images_new/banners/");
  $uploadObj->setResize("true", 200, 200);
  $uploadObj->setMaxSize(1000);
  $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png");
  $uploadObj->setRename("auto");
  return $uploadObj->Execute();
}
//end Trigger_ImageUpload trigger
 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
			$theValue = ($theValue != "") ? "'" . date("Y-m-d",strtotime($theValue)) . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
 
$query_reports = "SELECT * FROM reports";
$reports = mysql_query($query_reports, $conn_database) or die(mysql_error());
$row_reports = mysql_fetch_assoc($reports);
$totalRows_reports = mysql_num_rows($reports);
 
// Make an insert transaction instance
$ins_reports = new tNG_insert($conn_conn_database);
$tNGs->addTransaction($ins_reports);
// Register triggers
$ins_reports->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_reports->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_reports->registerTrigger("END", "Trigger_Default_Redirect", 99, "update_success.php");
$ins_reports->registerTrigger("AFTER", "Trigger_ImageUpload", 98);
 
// Add columns
$ins_reports->setTable("reports");
$ins_reports->addColumn("companyid", "STRING_TYPE", "POST", "rcompany");
$ins_reports->addColumn("title", "STRING_TYPE", "POST", "reports_title");
$ins_reports->addColumn("year", "STRING_TYPE", "POST", "reports_year");
$ins_reports->addColumn("month", "STRING_TYPE", "POST", "reports_month");
$ins_reports->addColumn("day", "STRING_TYPE", "POST", "reports_day");
$ins_reports->addColumn("shortDesc", "STRING_TYPE", "POST", "reports_desc");
$ins_reports->addColumn("reportBody", "STRING_TYPE", "POST", "reports_content");
$ins_reports->addColumn("websiteLink", "STRING_TYPE", "POST", "reports_websiteLink");
$ins_reports->addColumn("mailLink", "STRING_TYPE", "POST", "reports_mailLink");
$ins_reports->addColumn("logo", "FILE_TYPE", "FILES", "logo");
$ins_reports->addColumn("published", "STRING_TYPE", "POST", "publish");
$ins_reports->addColumn("report", "STRING_TYPE", "POST", "report");
$ins_reports->setPrimaryKey("id", "NUMERIC_TYPE");
 
// Execute all the registered transactions
$tNGs->executeTransactions();
 
// Get the transaction recordset
$rsreports = $tNGs->getRecordset("reports");
$row_rsreports = mysql_fetch_assoc($rsreports);
$totalRows_rsreports = mysql_num_rows($rsreports);

Open in new window

0
jonathan-dunstans
Asked:
jonathan-dunstans
  • 2
1 Solution
 
agamalCommented:
kindly find my answer in this question .. it may help ... any further details send me ...



http://www.experts-exchange.com/Web_Development/Miscellaneous/Q_24147029.html

Open in new window

0
 
jonathan-dunstansAuthor Commented:
0
 
agamalCommented:
as you like ... but the solution i recommended was the one i post ... so i can provide support for it
as a lto here regarding uploading images or files


anyway suite yourself and good luck   :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now