Current location: Hot Scripts Forums » Programming Languages » PHP » inserting Filename + extension into the database


inserting Filename + extension into the database

Reply
  #1 (permalink)  
Old 07-18-04, 07:44 AM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
inserting Filename + extension into the database

Ok I have a register.php. And what Im trying too do is when a user uploads an image from there computer, Im trying too get that filename plus the extension and inserting it into the database. (eg: images/picture2.jpg) Would anybody know what I could do?

PHP Code:

<?php 

if (isset($_FILES['imageFile'])) {
    
$KW_max_size=9000000000;
    
$extension="";
    if (
is_uploaded_file($_FILES['imageFile']['tmp_name'])) { 
        if(
$_FILES['imageFile']['size'] <= $KW_max_size) { 
            
$realname $_FILES['imageFile']['name']; 
            
$ext_array =explode(".",$realname);
            
$last_position count($ext_array) - 1
            
$extension $ext_array[$last_position];
            
$extAllowed=array ('all');
            
$ii=count($extAllowed); 
            
$flag=0;
            for(
$i=0;$i<$ii;$i++){ 
                if (
$extAllowed[$i]==$extension)
                    
$flag=1;
            }
            if (
$extAllowed[0]=="all")
                
$flag=1;
            if(
copy($_FILES['imageFile']['tmp_name'], "../../robslounge (Local Server)/ImagesUploaded/".$realname) && $flag==1) { 
                
Header("Location: "); 
                 } else 
Header("Location: "); 
        } else 
Header("Location: ");
    } else     
Header("Location: ");
}
?>
<?php 
require_once('MainConnection.php'); ?>
<?php
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset(
$_POST[$MM_flag])) {
  
$MM_dupKeyRedirect="AlreadyExistName.php";
  
$loginUsername $_POST['requiredusername'];
  
$LoginRS__query "SELECT username FROM dbusers WHERE username='" $loginUsername "'";
  
mysql_select_db($database_MainConnection$MainConnection);
  
$LoginRS=mysql_query($LoginRS__query$MainConnection) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);
  
//if there is a row in the database, the username was found - can not add the requested username
  
if($loginFoundUser){
    
$MM_qsChar "?";
    
//append the username to the redirect page
    
if (substr_count($MM_dupKeyRedirect,"?") >=1$MM_qsChar "&";
    
$MM_dupKeyRedirect $MM_dupKeyRedirect $MM_qsChar ."requsername=".$loginUsername;
    
header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}
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 ((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['imageFile'], "text"),
                       
GetSQLValueString($_POST['UserDetail'], "text"),
                       
GetSQLValueString($_POST['hobbiesInterest'], "text"),
                       
GetSQLValueString($_POST['favQuote'], "text"),
                       
GetSQLValueString($_POST['registeredDate'], "text"));
  
mysql_select_db($database_MainConnection$MainConnection);
  
$Result1 mysql_query($insertSQL$MainConnection) or die(mysql_error());
  
$insertGoTo "thanks.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
<?php
//***************************************************************** 
# This code is for the date according too the computers setted time
$today date("M d Y"); 
//*****************************************************************
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>(((&lt;o&gt;_&lt;o&gt;))) .:.:.:.:. R e g i s t e r .:.:.:.:.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
body {
 background-color: #6600FF;
}
body,td,th {
 font-family: Arial, Helvetica, sans-serif;
 color: #CCFF00;
 font-size: 10px;
 font-weight: bold;
}
-->
</style>
<link href="register_design.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style3 {font-size: 14px}
.style4 {font-size: 16px}
.style5 {font-size: 12px}
-->
</style>
<script>
function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("One or more of the required elements are not completed. Please complete them, then submit again!")
return false
}
else
return true
}
</script>
</head>
<body>
<p align="center"><span class="style4">RULES:</span></p>
<p align="center" class="style5">When you register as a member you get the following privileges (membership is obviously free!) <br />
    <br />
  * view hidden content (journal) <br />
  * Read and Post announcements/events<br />
  * Text message Rob directly too his cell from a page<br />
  * View people's penpal profiles<br />
  * Birthday wishes announcements<br />
  * Join Contest and win prizes!! </p>
<p align="center" class="style5">DO NOT abuse the announcements page by fluiding up useless information that is not beneficial too read</p>
<p align="center" class="style5">Do not post anything that can offended the users of this webpage (race, weight, color, religious, disabilities...)</p>
<p align="center" class="style5">If you chose too abuse any of the rules, then you will lose your membership.</p>
<p align="center" class="style5"><u>YOUR IP ADDRESS WHICH WILL GET LOGGED</u>: <b><font face="Arial, Helvetica, sans-serif" size="1" color="#6699FF">
  <?php
print (' '.$REMOTE_ADDR.'.');
?>
</font></b></p>
<table width="361" border="1" bordercolor="#000000" bgcolor="#333333">
  <tr>
    <td>Register</td>
  </tr>
</table>
<form action="/robslounge (Local Server)/account/register.php" method="POST" enctype="multipart/form-data" name="form1"" onfiltered="return checkrequired(this)"form1>
  <table width="897" height="258" border="0" bordercolor="#000000">
    <tr valign="top">
      <td width="416" height="254"><p>* First name: 
          <input name="requiredfirstname" type="text" id="requiredusername" />
      </p>
        <p>* Last Name: 
          <input name="requiredlastname" type="text" id="requiredusername2" />    
        </p>
        <p><span class="style3">*</span> username:
            <input name="requiredusername" type="text" id="username4" />
        </p>
        <p> <span class="style3">*</span> password:
            <input name="requiredpassword" type="password" id="password3" />
        </p>
        <p> <span class="style3">*</span> email:
            <input name="requiredemail" type="text" id="email3" />
        </p>
        <p>  msn messenger: 
          <input name="msn" type="text" id="email" />
</p>
        <p align="right">
          <input name="registeredDate" type="hidden" class="NameForm" id="registeredDate" value="<?php echo $today ?>" />
</p>
      </td>
      <td width="471"><p>yahoo messenger:
          <input name="yahoo" type="text" id="yahoo" />
        </p>
        <p>aim: 
            <input name="aim" type="text" id="aim2" />
        </p>        <p>
          icq: 
          <input name="icq" type="text" id="icq" />
        </p>
        <p>
          location: 
          <input name="location" type="text" id="location" />
        </p>
        <p>
          birthday: 
          <input name="birthday" type="text" id="birthday" />
</p>                
        <p> Homepage:
<input name="homepage" type="text" id="homepage" value="http://" />
</p>
<p>images: 
  <input name="imageFile" type="file" id="images" />
      <br />
      <br />
      <input name="PrivledgeLevel" type="hidden" id="PrivledgeLevel3" value="member" /> 
      <br />
  </p></td>
    </tr>
  </table>
  <!-- You need this script for the function too work so when the user clicks on submit
       it will forward you too the Thank You Page -->
  <div align="center">    <br />
    <table width="783" border="0" align="left">
      <tr>
        <td width="9" height="228"><div align="center">
        </div></td>
        <td width="401" valign="top"><p>A little about you!! <br />
            <textarea name="UserDetail" cols="50" rows="12" id="textarea4"></textarea>
        </p>
        </td>
        <td width="359" valign="top"><p>Hobbies and Interest <br />
            <textarea name="hobbiesInterest" cols="50" rows="12" id="textarea10"></textarea>
        </p>        </td>
      </tr>
    </table>
    <p>
      <input type="hidden" name="submit" value="true" />
    </p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p align="left">&nbsp;</p>
    <p align="left">&nbsp;</p>
    <table width="825" border="0" align="left">
      <tr>
        <td width="32"><p>&nbsp;</p>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          <p><br />
          </p></td>
        <td width="771" valign="top">
          <div align="center">Favourite Quote!! <br />
              <textarea name="favQuote" cols="50" rows="12" id="textarea20"></textarea>
            <br />
              <br />
              <input type="submit" name="Submit" value="Submit" />      
          </div></td>
        <td width="10">&nbsp;</td>
      </tr>
    </table>
    <p align="left">&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;    </p>
    <p>      
      <!-- *********************************************************************************-->
      <input type="hidden" name="MM_insert" value="form1">
    </p>
  </div>
</form>
</body>
</html>
If anybody knows, please alert me ASAP
RoB
Reply With Quote
  #2 (permalink)  
Old 07-18-04, 08:19 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
something like this??
PHP Code:

if (isset($_FILES['imageFile'])) {

    
$KW_max_size=9000000000;
    
$extension="";
    if (
is_uploaded_file($_FILES['imageFile']['tmp_name'])) { 
        if(
$_FILES['imageFile']['size'] <= $KW_max_size) { 
            
$realname $_FILES['imageFile']['name'];
            
            
$file_extension $_FILES['imageFile']['type'];
            
$extensions = array("image/gif""image/jpg""image/jpeg""image/png"); // accepted extensions
            
if (in_array($file_extension$extensions)) {
                
$flag 1;
            }
            if(
move_uploaded_file($_FILES['imageFile']['tmp_name'], "../../robslounge (Local Server)/ImagesUploaded/".$realname) && $flag==1) { 
                
header("Location: "); 
                 } else 
header("Location: "); 
        } else 
header("Location: ");
    } else     
header("Location: ");

then insert $realname and $file_extension
Reply With Quote
  #3 (permalink)  
Old 07-19-04, 05:46 AM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
Im sorry but I dont quite understand. Where would I insert $realname and
$extension in there.
Reply With Quote
  #4 (permalink)  
Old 07-20-04, 12:10 PM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
OMG... This is too simple. I'm sure you didn't write the code so you don't know that the code itself has generated file extension.

PHP Code:

if (isset($_FILES['imageFile'])) { 

    
$KW_max_size=9000000000
    
$extension=""
    if (
is_uploaded_file($_FILES['imageFile']['tmp_name'])) { 
        if(
$_FILES['imageFile']['size'] <= $KW_max_size) { 
            
/****** Below is the filename, i.e. name + extension **************/
            
$realname $_FILES['imageFile']['name']; 
             
/****** Below is the file extension ***************************/
            
$file_extension $_FILES['imageFile']['type']; 
            
$extensions = array("image/gif""image/jpg""image/jpeg""image/png"); // accepted extensions 
            
if (in_array($file_extension$extensions)) { 
                
$flag 1
            } 
            if(
move_uploaded_file($_FILES['imageFile']['tmp_name'], "../../robslounge (Local Server)/ImagesUploaded/".$realname) && $flag==1) { 
                
/**
                  * If you want to insert the file and its extension, do it here
                  * mysql_query("your_query_goes_here");
                  *
                  */
                
header("Location: "); 
                 } else 
header("Location: "); 
        } else 
header("Location: "); 
    } else     
header("Location: "); 

Reply With Quote
  #5 (permalink)  
Old 07-20-04, 01:38 PM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
Ok I'll reedit this post since this guy was nice in replying too my other post. But still dawg, you shouldnt come up acting a smart and $h!t just because someone doesnt understand somethin. And yes I did use the server behaviours for making my php website and you know what....there is nothing wrong with that.

Last edited by mcrob; 07-20-04 at 01:54 PM.
Reply With Quote
  #6 (permalink)  
Old 07-21-04, 03:22 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mcrob
And yes I did use the server behaviours for making my php website and you know what....there is nothing wrong with that.
you are right.. there is nothing wrong with it.. but.. writeing your own code makes you learn more in shorter time.. honestly i did use it also.. but trying not to becourse if i write my own i dont only learn new things.. i also know exactly what happens where.. as a suggestion i highly recommend starting to avoid useing it..

Wille
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
php/mysql inserting twice into database with IE 6 sky4est PHP 3 04-22-04 12:46 PM
Add an extension to a number from a database Bonzo PHP 2 02-20-04 11:38 AM
form not inserting information into the database sabret00the PHP 7 12-01-03 03:35 PM


All times are GMT -5. The time now is 04:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.