Hi there, am new to php and i have been trying to upload files from a form to a location on a server ( folder "uploads" on the server), the syntax and everything i am using is right cos i tried using just a form but when ever i use it here it just doesn't upload. Can some one please help me out. The whole code for the page is below. thank you

<?php require_once('Connections/project_database.php'); ?>
<?php

/*Session starts so as to access unique email from personal details form*/
session_start();
$email = $_SESSION['form1']['email'];

/*To upload pictures and video to server*/
if($_POST[upload]=="1")
{
	$to ="uploads/".$_FILES['picture']['name'];
	move_uploaded_file($_FILES['picture']['tmp_name'], $to);
        
        $to ="uploads/".$_FILES['picture2']['name'];
	move_uploaded_file($_FILES['picture2']['tmp_name'], $to);

        $to ="uploads/".$_FILES['picture3']['name'];
	move_uploaded_file($_FILES['picture3']['tmp_name'], $to);

       $to ="uploads/".$_FILES['video']['name'];
	move_uploaded_file($_FILES['video']['tmp_name'], $to);
}


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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;
}
}


mysql_select_db($database_project_database, $project_database);
$query_rsEmail = "SELECT personal.email FROM personal WHERE personal.email='$email'";
$rsEmail = mysql_query($query_rsEmail, $project_database) or die(mysql_error());
$row_rsEmail = mysql_fetch_assoc($rsEmail);
$totalRows_rsEmail = mysql_num_rows($rsEmail);

$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 property (email, certNo, proptype, propintent, rooms, plotsize, price, `add`, `state`, lga, picture, picture2, picture3, video) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['certNo'], "text"),
                       GetSQLValueString($_POST['proptype'], "text"),
                       GetSQLValueString($_POST['propintent'], "text"),
					   GetSQLValueString($_POST['rooms'], "int"),
                       GetSQLValueString($_POST['plotsize'], "int"),
                       GetSQLValueString($_POST['price'], "int"),
                       GetSQLValueString($_POST['add'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['lga'], "text"),
                       GetSQLValueString($_POST['picture'], "text"),
					   GetSQLValueString($_POST['picture2'], "text"),
					   GetSQLValueString($_POST['picture3'], "text"),
                       GetSQLValueString($_POST['video'], "text"));

  mysql_select_db($database_project_database, $project_database);
  $Result1 = mysql_query($insertSQL, $project_database) or die(mysql_error());
  
  
  
   
  
  $insertGoTo = "confirm.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?><!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:: Property Registration ::</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script src="SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="container">

<div id="header"><br />
<br />
<br />
 </div>

<div id="menu">
</div>
  <div id="othersmain">
    <h1>Registration</h1>
    <p>Continue registration some other time? <a href="index.html">yes</a></p>
    <form action="<?php echo $editFormAction; ?>" method="POST"  name="form1" id="form1" encytype="multipart/form-data">
    <input type="hidden" name="upload" value="1" />

      <table width="526" border="0" align="center">
  <caption>
          Property Details
        </caption>
   
       <input name="email" type="hidden" value="<?php echo $row_rsEmail['email']; ?>"/>
        
        <tr>
          <td width="251">Cert. of Occupancy No. :</td>
          <td width="259"><span id="sprytextfield1">
            <label>
            <input name="certNo" type="text" id="certNo" size="30" />
            </label>
          <span class="textfieldRequiredMsg">A value is required.</span></span></td>
        </tr>
        <tr>
          <td>Type of property :</td>
          <td><select name="proptype" id="proptype">
            <option>- Property Type -</option>
            <option>bungalow</option>
            <option>flat</option>
            <option>storey</option>
            <option>plot</option>
            <option>shop</option>
          </select></td>
        </tr>
        <tr>
          <td>Intent for advertisement :</td>
          <td align="left"><select name="propintent" id="propintent">
            <option selected="selected">- Select Category-</option>
            <option>sell</option>
            <option>lease</option>
          </select></td>
        </tr>
        <tr>
          <td>Number of Rooms :</td>
          <td>
          <label>
          <input name="rooms" type="text" id="rooms" size="30" />
          </label>
          </td>
        </tr>
        <tr>
          <td>Plot Size :</td>
          <td><span id="sprytextfield3">
          <input name="plotsize" type="text" id="plotsize" size="30" />
          <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>SQM</td>
        </tr>
        <tr>
          <td>Price (=N=) :</td>
          <td align="left"><span id="sprytextfield4">
          <label>
          <input name="price" type="text" id="price" size="30" />
          </label>
          <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">1,000,000.00.</span></span></td>
        </tr>

        <tr>
          <td>Address :</td>
          <td><span id="sprytextfield5">
            <label>
            <input name="add" type="text" id="add" size="30" />
            </label>
          <span class="textfieldRequiredMsg">A value is required.</span></span></td>
        </tr>
        <tr>
          <td>State :</td>
          <td><label>
            <select name="state" id="state">
              <option selected="selected">- State -</option>
              <option>Abia</option>
              <option>Adamawa</option>
              <option>Akwa Ibom</option>
              <option>Anambra</option>
              <option>Bauchi</option>
              <option>Bayelsa</option>
              <option>Benue</option>
              <option>Borno</option>
              <option>Cross River</option>
              <option>Delta</option>
              <option>Ebonyi</option>
              <option>Edo</option>
              <option>Ekiti</option>
              <option>Enugu</option>
              <option>Gombe</option>
              <option>Imo</option>
              <option>Jigawa</option>
              <option>Kaduna</option>
              <option>Kano</option>
              <option>Katsina</option>
              <option>Kebbi</option>
              <option>Kogi</option>
              <option>Kwara</option>
              <option>Lagos</option>
              <option>Nasarawa</option>
              <option>Niger</option>
              <option>Ogun</option>
              <option>Ondo</option>
              <option>Osun</option>
              <option>Oyo</option>
              <option>Plateau</option>
              <option>Rivers</option>
              <option>Sokoto</option>
              <option>Taraba</option>
              <option>Yobe</option>
              <option>Zamfara</option>
              <option>F.C.T</option>
            </select>
          </label></td>
        </tr>
        <tr>
          <td>Local Govt. Area :</td>
          <td><span id="sprytextfield6">
            <label>
            <input name="lga" type="text" id="lga" size="30" />
            </label>
          <span class="textfieldRequiredMsg">Ps Enter Local Govt. Area.</span></span></td>
        </tr>
        <tr>
          <td>Picture :</td>
          <td><label>
          
            <input name="picture" type="file" id="picture" size="30" />
            
          </label></td>
        </tr>
        <tr>
          <td>Picture :</td>
          <td><input name="picture2" type="file" id="picture2" size="30" /></td>
        </tr>
        <tr>
          <td>Picture :</td>
          <td><input name="picture3" type="file" id="picture3" size="30" /></td>
        </tr>
        <tr>
          <td>Video :</td>
          <td><label>
            <input name="video" type="file" id="video" size="30" />
          </label></td>
        </tr>
        <tr>
          <td colspan="2"><div align="center">
              <label>
              <input type="submit" name="property" id="property" value="Make Entry" />
              </label>
          </div></td>
        </tr>
      </table>
      
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
   
    
    <!-- end #mainContent --></div>
  <div id="footer">
    <p>&copy;2008  &nbsp;<span class="separator">|</span> &nbsp; 
Ibrahim Suleiman Sani (0613075)</p>
  <!-- end #footer --></div>
<!-- end #container --></div>

<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["change"]});
var  = new Spry.Widget.ValidationTextField("", "integer", {validateOn:["change"]});
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "integer", {validateOn:["change"]});
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "currency", {validateOn:["change"]});
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "none", {validateOn:["change"]});
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "none", {validateOn:["change"]});
//-->
</script>
</body>
</html>
<?php
mysql_free_result($rsEmail);
?>

I will write out the code necessary to upload files. It's going to take me quite some time. So, be a little patient, please.

Hi ibrahimssani,

Here is the script to upload your files. You can edit the maximum upload size to suit your needs. Also you can edit the file types you want uploaded. I included .gif, .pjpeg and .jpeg but you may like to add more file formats.

This form compares the MIME type against others by using $HTTP_POST_FILES variable. If the file type doesn't match, the user is warned to choose another file format that is supported.

The following moves the file from a temporary directory into the uploads directory using the supplied filename:
move_uploaded_file($HTTP_POST_FILES,
"uploads/".$HTTP_POST_FILES);

As an added security, the move_uploaded_file() function checks to make sure the file was actually uploaded via PHP's HTTP POST upload process. This is a preferred function to copying the file and then deleting the original.

To prevent abuse of the upload processing script, it validates pressing the submit button. I hope this will solve your need.

<?php
$maxsize=28480; // Set the maximum upload size in bytes
if (!$HTTP_POST_VARS['submit']) {
    //print_r($HTTP_POST_FILES);
	$error=" ";
	// This will cause the rest of the process to be skipped
	//and the upload form displays
}
if (!is_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name']) AND
!isset($error)) {
    $error = "<b>You must upload a file!</b><br /><br />";
	unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
}
if ($HTTP_POST_FILES['upload_file']['size'] > $maxsize AND !isset($error)) {
    $error = "<b>Error, file must be less than $maxsize bytes.</b><br /><br />";
	unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
}
if($HTTP_POST_FILES['upload_file']['type'] != "image/gif" AND
$HTTP_POST_FILES['upload_file']['type'] != "image/pjpeg" AND
$HTTP_POST_FILES['upload_file']['type'] !="image/jpeg" AND !isset($error)) {
    $error = "<b>You may only upload .gif or .jpeg files.<b><br /><br />";
	unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
}
if (!isset($error)) {
    move_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name'],
	                   "uploads/".$HTTP_POST_FILES['upload_file']['name']);
	print "Thank you for your upload.";
	exit;
}
else
{
    echo ("$error");
}
?>

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The title of your page goes here</title>
</head>

<body>
<form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF']))?>" method="post"
enctype="multipart/form-data">
    Choose a file to upload:<br />
	<input type="file" name="upload_file" size="50" />
	<br />
	<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

I will write out the code necessary to upload files. It's going to take me quite some time. So, be a little patient, please.

Thank you so much. The problem has been solved.

Hello ibrahimssani,

Since the issue of this thread has been resolved, you may want to mark it as "Solved", owing to the fact that you're the thread starter. Doing this prevents people from posting anymore replies to this solved thread.

hi there it's me again. Am having problems again, file uploads is fine but apparently i cannot get my sql database to store the names of the uploaded files.

This question has already been answered. Start a new discussion instead.