Quantcast
Channel: Adobe Community : All Content - PHP Application Development (read only)
Viewing all articles
Browse latest Browse all 107

How to upload an image in a directory using PHP code generated by Dreamweaver?

$
0
0

I have created a dynamic website with Dreamweaver and PHP, i have also created a insertform page using dreamweaver's 'Record Insertion Form Wizard' i have a field named prod_img in my MySQL database and on my form but this is a text field and i have to enter the path of the image directory to display it but this needs to have the image in the directory, i want to add a browse file field so that the image uploads to the directory by PHP.

My code is as follows:


<?php require_once('../Connections/dwtltd.php'); ?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{  if (PHP_VERSION < 6) {    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;  }  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 != "") ? "'" . $theValue . "'" : "NULL";      break;    case "defined":      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;      break;  }  return $theValue;
}
}


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {  $insertSQL = sprintf("INSERT INTO special_offers (spec_img, spec_head, spec_desc, spec_call, spec_price, spec_rtn) VALUES (%s, %s, %s, %s, %s, %s)",                       GetSQLValueString($_POST['spec_img'], "text"),                       GetSQLValueString($_POST['spec_head'], "text"),                       GetSQLValueString($_POST['spec_desc'], "text"),                       GetSQLValueString($_POST['spec_call'], "text"),                       GetSQLValueString($_POST['spec_price'], "text"),                       GetSQLValueString($_POST['spec_rtn'], "text"));  mysql_select_db($database_dwtltd, $dwtltd);  $Result1 = mysql_query($insertSQL, $dwtltd) or die(mysql_error());  $insertGoTo = "../specialoffers.php";  if (isset($_SERVER['QUERY_STRING'])) {    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";    $insertGoTo .= $_SERVER['QUERY_STRING'];  }  header(sprintf("Location: %s", $insertGoTo));
}


mysql_select_db($database_dwtltd, $dwtltd);
$query_insertRS = "SELECT * FROM special_offers ORDER BY spec_id ASC";
$insertRS = mysql_query($query_insertRS, $dwtltd) or die(mysql_error());
$row_insertRS = mysql_fetch_assoc($insertRS);
$totalRows_insertRS = mysql_num_rows($insertRS);


?>

 

 

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">  <table align="center" cellpadding="5">    <tr valign="baseline">      <td align="right" nowrap="nowrap">Add Image:</td>      <td><span id="sprytextfield1">      <input type="text" name="spec_img" value="" size="32" />      <span class="textfieldRequiredMsg">A value is required.</span></span></td>    </tr>    <tr valign="baseline">      <td nowrap="nowrap" align="right">Offer Heading:</td>      <td><input type="text" name="spec_head" value="" size="32" /></td>    </tr>    <tr valign="baseline">      <td nowrap="nowrap" align="right">Offer Description:</td>      <td><input type="text" name="spec_desc" value="" size="32" /></td>    </tr>    <tr valign="baseline">      <td nowrap="nowrap" align="right">Phone:</td>      <td><input type="text" name="spec_call" value="" size="32" /></td>    </tr>    <tr valign="baseline">      <td nowrap="nowrap" align="right">Price:</td>      <td><input type="text" name="spec_price" value="" size="32" /></td>    </tr>    <tr valign="baseline">      <td nowrap="nowrap" align="right">RTN:</td>      <td><input type="text" name="spec_rtn" value="" size="32" /></td>    </tr>    <tr valign="baseline">      <td nowrap="nowrap" align="right"> </td>      <td><input type="submit" value="Insert record" /></td>    </tr>  </table>  <input type="hidden" name="MM_insert" value="form1" /></form>

 

Help greatly appreciated.

 

I have googled, yahooed, binged etc etc and tried many tutorials but nothing goes in my favor please do not suggest to search on search engines or websites.


Viewing all articles
Browse latest Browse all 107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>