inserting filename plus extension into database

inserting filename plus extension into database

Post by Mcro » Sat, 09 Oct 2004 15:19:24

Ok people for anyone that uses Server Behaviors in Dreamweaver MX 2004 for
making complex websites lets say PHP and MySQL for example, you have an file
field and you want users too upload image avatars. Now lets say you already
know how too insert files into your folder in the web server but you dont know
how too insert the filename plus the extension into the database.
If you know about carrying variables from the textfield ( $POST['username']; )
within the form then you will know about this.....

$_FILES['imageupload']['name']; = gets the name of the file
$_FILES['imageupload']['tmp_name'] = the temporary name file of which was
uploaded too the server
$_FILES['imageupload']['type'] = the mime type of file etc: image/gif,
text/css, image/jpeg etc
$_FILES['imageupload']['size'] = gets the size of the file in bytes

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO dbusers (firstName, LastName, username,
password, PrivledgeLevel, email, msn, yahoo, aim, icq, location, birthday,
homepage, images, UserDetail, hobbiesInterest, FavQuote, RegisteredDate) VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['requiredfirstname'], "text"),
GetSQLValueString($_POST['requiredlastname'], "text"),
GetSQLValueString($_POST['requiredusername'], "text"),
GetSQLValueString($_POST['requiredpassword'], "text"),
GetSQLValueString($_POST['PrivledgeLevel'], "text"),
GetSQLValueString($_POST['requiredemail'], "text"),
GetSQLValueString($_POST['msn'], "text"),
GetSQLValueString($_POST['yahoo'], "text"),
GetSQLValueString($_POST['aim'], "text"),
GetSQLValueString($_POST['icq'], "text"),
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['birthday'], "text"),
GetSQLValueString($_POST['homepage'], "text"),
GetSQLValueString($_POST['UserDetail'], "text"),
GetSQLValueString($_POST['hobbiesInterest'], "text"),
GetSQLValueString($_POST['favQuote'], "text"),
GetSQLValueString($_POST['registeredDate'], "text"));

When dealing with the file field, it is quite different from working with a
normal text field....... If you want too insert the filename plus the extension
into the database, you must use the $_FILES['imageupload']['name']

It is quite good too get use too the IF's and the ELSE'S statements so you can
validate the file field weither the file size is too huge or if they are
uploading the wrong extension etc. I hope this helps.