I am using Dreamweaver to create a form that will upload images of properties we have for sale. Many say it is better to save the link to the uploaded image that the user uploads to a directory. That is fine and dandy...I searched everywhere I I can not find a way to modify the code Dreamweaver creates to do this. I am new at PHP...but all other info works and displays dynamically. Whe I upload a picture...it stores the path to my hard drive rather than storing the image in the table itself or storing it in a directory and then storing the path or url in the table.
What I wish to do is:
Allow users to upload three images into a specified directory called listimages
rename the filenames so that each has a unique filename perhaps using other data inserted in the form such as ID and county and then before storing it in the directory
Copy the new filenames and add ithem as a url into my table called land_listings as imag1url, image2url, image3url with the path listimages/$image1url... where listimages it the directory the images are stored and $imageurl is the nename of the file
I am not concerned with the type of images or file sizes since only agents will be authorized to upload images.
I attached a copy of the code Dreamweaver created. Any help will be appreciated and compenstaed if necessary. Everyone says it is easy to do...I just haven't seen it coded yet.
Thanks in advance
from there I can handle getting the image out again...
Here is the code Dreamweaver created:
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 != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO land_listings (title, status, type, county, town, acres, price, agent, description, image1url) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['title'], "text"),
GetSQLValueString($HTTP_POST_VARS['status'], "text"),
GetSQLValueString($HTTP_POST_VARS['type'], "text"),
GetSQLValueString($HTTP_POST_VARS['county'], "text"),
GetSQLValueString($HTTP_POST_VARS['town'], "text"),
GetSQLValueString($HTTP_POST_VARS['acres'], "double"),
GetSQLValueString($HTTP_POST_VARS['price'], "text"),
GetSQLValueString($HTTP_POST_VARS['agent'], "text"),
GetSQLValueString($HTTP_POST_VARS['description'], "text"),
GetSQLValueString($HTTP_POST_VARS['image1url'], "text"));
mysql_select_db($database_list, $list);
$Result1 = mysql_query($insertSQL, $list) or die(mysql_error());
$insertGoTo = "http://www.blueheronrealtyinc.com/landlistings.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="495" height="38" colspan="3" valign="top">
<div align="center"><strong><font size="+2">Upload Your Lot/Land Listing(s)
Here!</font></strong></div>
</td>
</tr>
<tr>
<td width="47" height="418" valign="top"></td>
<td width="419" height="418" valign="top">
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Title:</td>
<td><input type="text" name="title" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Status:</td>
<td>
<select name="status">
<option value="Active" >Active</option>
<option value="Under Contract" >Under Contract</option>
<option value="Sold" >Sold</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Type:</td>
<td>
<select name="type">
<option value="Lot" >Lot</option>
<option value="Land" >Land</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">County:</td>
<td><input type="text" name="county" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Town:</td>
<td><input type="text" name="town" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Acres:</td>
<td><input type="text" name="acres" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Price:</td>
<td><input name="price" type="text" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Agent:</td>
<td><input type="text" name="agent" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td height="106" align="right" valign="top" nowrap>Description:</td>
<td>
<textarea name="description" cols="50" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Photo::</td>
<td><input name="image1url" type="file" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert Record">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</td>
<td width="29" height="418" valign="top"></td>
</tr>
<tr>
<td width="47" height="1" valign="top"><img src="../agentlisting/transparent.gif" alt="" width="47" height="1"></td>
<td width="419" height="1" valign="top"><img src="../agentlisting/transparent.gif" alt="" width="419" height="1"></td>
<td width="29" height="1" valign="top"><img src="../agentlisting/transparent.gif" alt="" width="29" height="1"></td>
</tr>
</table>
</body>
</html>