PHP form upload script

Posted on 2009-02-18
Last Modified: 2013-12-12
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




// Start trigger

$formValidation = new tNG_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->setResize("true", 200, 200);


  $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png");


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


    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";


    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";


    case "date":

			$theValue = ($theValue != "") ? "'" . date("Y-m-d",strtotime($theValue)) . "'" : "NULL";


    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;



  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);


// 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->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


// Get the transaction recordset

$rsreports = $tNGs->getRecordset("reports");

$row_rsreports = mysql_fetch_assoc($rsreports);

$totalRows_rsreports = mysql_num_rows($rsreports);

Open in new window

Question by:jonathan-dunstans
    LVL 8

    Expert Comment

    kindly find my answer in this question .. it may help ... any further details send me ...

    Open in new window


    Accepted Solution

    LVL 8

    Expert Comment

    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   :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now