PDA

View Full Version : Inserting 'file' into a form (100 POSTS!!! WOO HOO)


kona72
06-13-2006, 07:21 PM
I have been playing with this for a while now and just about have it....
I need to be able to browse for a file on a hard drive and then have it plus the rest of the info submitted saved to a database and folder.

Here is my code so far....

<?php require_once('Connections/curvesConn.php'); ?>
<?php
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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

{ if(is_uploaded_file($_FILES[upload][tmp_name]))
{
$dt=date("YmdHis");
$file=$dt.$_FILES[upload][name];
copy($_FILES[upload][tmp_name],"discount/$file");
}}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO discount (disc_key, image, http, `desc`) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['disc_key'], "int"),
GetSQLValueString($_FILES['upload'], "text"),
GetSQLValueString($_POST['http'], "text"),
GetSQLValueString($_POST['desc'], "text"));

mysql_select_db($database_curvesConn, $curvesConn);
$Result1 = mysql_query($insertSQL, $curvesConn) or die(mysql_error());

$insertGoTo = "curves_discount_club.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">


</p>
<table width="90%" border="0" cellspacing="0" cellpadding="8">
<tr>
<td width="25%"></td>
<td width="75%"><input name="disc_key" type="hidden" id="disc_key"></td>
</tr>
<tr>
<td>Upload Image</td>
<td><input name="upload" type="file" id="upload"></td>
</tr>
<tr>
<td>Website Address: </td>
<td><input name="http" type="text" id="http"></td>
</tr>
<tr>
<td>Description:</td>
<td><input name="desc" type="text" id="desc"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit2" value="Submit"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>

</body>
</html>


My only issue is that instead of uploading the actual file... it is uploading the path as text.

Any Ideas????

Oh Yeah HURRAY 100 Posts!!!

kona72
06-14-2006, 02:12 PM
Anyone??

davidj
07-05-2006, 03:00 PM
ENCTYPE="multipart/form-data"

this is missing from your form tag which could be causing problems

davidj
07-05-2006, 03:01 PM
high five for the 100 posts

davidj
07-05-2006, 03:01 PM
although there is people on here that cheat to build up there posts scores

davidj
07-05-2006, 03:02 PM
which is very shite thing to do

kona72
07-05-2006, 04:49 PM
who

kona72
07-05-2006, 04:49 PM
would? :D

mrclark0
07-05-2006, 06:27 PM
which is very shite thing to do

LoL.