Jump to content

Recommended Posts

I have finally worked out how to upload images and there names into a sql database. :)

Question is how do i set the directory in which the images are posted?

 

At present they are uploaded into the admin section of my site here the php file is, not really were i want ppl accessing the file from...

 

Heres the code

 

<?php 



//This gets all the other information from the form 
$name=$_POST['name']; 
$suburb=$_POST['suburb']; 
$price=$_POST['price']; 
$content=$_POST['content']; 
$uploadFile0=($_FILES['uploadFile0']['name']); 
$uploadFile1=($_FILES['uploadFile1']['name']);
$uploadFile2=($_FILES['uploadFile2']['name']);
$uploadFile3=($_FILES['uploadFile3']['name']);
$uploadFile4=($_FILES['uploadFile4']['name']);
$uploadFile5=($_FILES['uploadFile5']['name']);
$uploadFile6=($_FILES['uploadFile6']['name']);
$uploadFile7=($_FILES['uploadFile7']['name']);
$uploadFile8=($_FILES['uploadFile8']['name']);



// Connects to your Database 
mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; 
mysql_select_db("gcproperty") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$uploadFile0', '$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; 


$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
// check if successfully copied
if($copy){
print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">";
} else{
echo "$file_name | could not be uploaded!<br>";
}
} // end of loop
?>



Link to comment
https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/
Share on other sites

move_uploaded_file() takes 2 arguments, a source file and a destination file.

 

So use something like this in your for loop:

 

// Full path to image directory
$path = '/usr/domain/public/images/';

// Move file to new location
move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name)

 

Incidently, there's an easier way to write this.  You could use an array from your form, rather than individual field names.  If you'd like further info then let me know.

 

Regards

Huggie

i used your code and added it mine as below

 

<?php 

//This is the directory where images will be saved 
$target = "../images/";

//This gets all the other information from the form 
$name=$_POST['name']; 
$suburb=$_POST['suburb']; 
$price=$_POST['price']; 
$content=$_POST['content']; 
$uploadFile0=($_FILES['uploadFile0']['name']); 
$uploadFile1=($_FILES['uploadFile1']['name']);
$uploadFile2=($_FILES['uploadFile2']['name']);
$uploadFile3=($_FILES['uploadFile3']['name']);
$uploadFile4=($_FILES['uploadFile4']['name']);
$uploadFile5=($_FILES['uploadFile5']['name']);
$uploadFile6=($_FILES['uploadFile6']['name']);
$uploadFile7=($_FILES['uploadFile7']['name']);
$uploadFile8=($_FILES['uploadFile8']['name']);



// Connects to your Database 
mysql_connect("localhost", "emediast", "7833pjer") or die(mysql_error()) ; 
mysql_select_db("emediast_gcproperty") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$uploadFile0', '$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; 


$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);


// Full path to image directory
$path = '../images';

// Move file to new location
move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name);


// check if successfully copied

if($copy){
print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">";
} else{
echo "$file_name | could not be uploaded!<br>";
}
} // end of loop
?>



 

It uploads the files and inserts the info into sql but still doesnt move the uploaded files to the new directory ../images

 

No errors reported either, any ideas?

 

Thanks for your help.

 

 

Replace this in your code

 

$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);

 

With this in my code

 

// Set pth to image directory
$path = '../images/';

// Move file to new location
move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name)

 

It should be that simple.

 

Regards

Huggie

 

Edit: I notice you're not stripping the path from the temp name, you'll want to do that too.

;);D

Your the best man, your awesome, problem solved!!

Thanks so so much, i have been on this for nights on end.

 

I dont mean to be asking too much but a simple filter for stopping the upload of something other that a gif, png or jpeg would be the icing on the cake.

 

Or should i re post?

 

So happy man, thanks again

You could base in on file extension...

 

<?php
// Check the extension is valid
if (preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadFile'. $x]['name']){
   // Add your adding to db and moving code here
}
else {
   // Add your error code here
   echo "Sorry, file must be of type .jpg .jpeg .gif or .png\n";
}
?>

 

Or there's a slightly more complex method using mime type.  Search these forums for that.

 

Regards

Huggie

Thanks 4 the speedy reply

 

Heres what i did with ur instructions

 

<?php 

//This is the directory where images will be saved 
$path = '../images/';

//This gets all the other information from the form 
$name=$_POST['name']; 
$suburb=$_POST['suburb']; 
$price=$_POST['price']; 
$content=$_POST['content']; 
$uploadFile0=($_FILES['uploadFile0']['name']); 
$uploadFile1=($_FILES['uploadFile1']['name']);
$uploadFile2=($_FILES['uploadFile2']['name']);
$uploadFile3=($_FILES['uploadFile3']['name']);
$uploadFile4=($_FILES['uploadFile4']['name']);
$uploadFile5=($_FILES['uploadFile5']['name']);
$uploadFile6=($_FILES['uploadFile6']['name']);
$uploadFile7=($_FILES['uploadFile7']['name']);
$uploadFile8=($_FILES['uploadFile8']['name']);



// Connects to your Database 
mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; 
mysql_select_db("gcproperty") or die(mysql_error()) ; 

// Check the extension is valid
if (preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadFile'. $x]['name']){


//Writes the information to the database

mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$uploadFile0', '$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; 


$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name);

}
else {
   // Add your error code here
   echo "Sorry, file must be of type .jpg .jpeg .gif or .png\n";
}




// check if successfully copied

if($copy){
print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">";
} else{
echo "$file_name | could not be uploaded!<br>";
}
} // end of loop
?>



 

But i get this error

 

Parse error: syntax error, unexpected '{' in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\add_test.php on line 28

 

I delete the { and i get this error Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\add_test.php on line 33

 

 

 

Sorry, typo...

 

Change this:

 

if (preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadFile'. $x]['name']){

 

To this:

 

if (preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadFile'. $x]['name'])){

 

Regards

Huggie

Huggie im so gratefull for your help but i did as u instructed and i get this error now

 

Parse error: syntax error, unexpected T_ELSE in C:\Program Files\Apache Group\Apache2\htdocs\gcproperty\admin\add_test.php on line 46

 

My full code is

<?php 

//This is the directory where images will be saved 
$path = '../images/';

//This gets all the other information from the form 
$name=$_POST['name']; 
$suburb=$_POST['suburb']; 
$price=$_POST['price']; 
$content=$_POST['content']; 
$uploadFile0=($_FILES['uploadFile0']['name']); 
$uploadFile1=($_FILES['uploadFile1']['name']);
$uploadFile2=($_FILES['uploadFile2']['name']);
$uploadFile3=($_FILES['uploadFile3']['name']);
$uploadFile4=($_FILES['uploadFile4']['name']);
$uploadFile5=($_FILES['uploadFile5']['name']);
$uploadFile6=($_FILES['uploadFile6']['name']);
$uploadFile7=($_FILES['uploadFile7']['name']);
$uploadFile8=($_FILES['uploadFile8']['name']);



// Connects to your Database 
mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ; 
mysql_select_db("gcproperty") or die(mysql_error()) ; 

// Check the extension is valid
if (preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadFile'. $x]['name'])){


//Writes the information to the database

mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$uploadFile0', '$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ; 


$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name);

}
else {
   // Add your error code here
   echo "Sorry, file must be of type .jpg .jpeg .gif or .png\n";
}




// check if successfully copied

if($copy){
print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">";
} else{
echo "$file_name | could not be uploaded!<br>";
}
} // end of loop
?>



 

Many thanks

You need to indent your code to make it more readable.

 

You're missing a closing curly bracket.  It's easier to see when indented correctly.  Try this...

 

<?php

//This is the directory where images will be saved
$path = '../images/';

//This gets all the other information from the form
$name=$_POST['name'];
$suburb=$_POST['suburb'];
$price=$_POST['price'];
$content=$_POST['content'];
$uploadFile0=($_FILES['uploadFile0']['name']);
$uploadFile1=($_FILES['uploadFile1']['name']);
$uploadFile2=($_FILES['uploadFile2']['name']);
$uploadFile3=($_FILES['uploadFile3']['name']);
$uploadFile4=($_FILES['uploadFile4']['name']);
$uploadFile5=($_FILES['uploadFile5']['name']);
$uploadFile6=($_FILES['uploadFile6']['name']);
$uploadFile7=($_FILES['uploadFile7']['name']);
$uploadFile8=($_FILES['uploadFile8']['name']);

// Connects to your Database
mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ;
mysql_select_db("gcproperty") or die(mysql_error()) ;

// Check the extension is valid
if (preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadFile'. $x]['name'])){

   //Writes the information to the database
   mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$uploadFile0', '$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ;

   $uploadNeed = $_POST['uploadNeed'];
   // start for loop
   for($x=0;$x<$uploadNeed;$x++){
      $file_name = $_FILES['uploadFile'. $x]['name'];
      
      // strip file_name of slashes
      $file_name = stripslashes($file_name);
      $file_name = str_replace("'","",$file_name);
      $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name);
   }
}
else {
   // Add your error code here
   echo "Sorry, file must be of type .jpg .jpeg .gif or .png\n";
}

// check if successfully copied

if($copy){
   print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">";
}
else{
   echo "$file_name | could not be uploaded!<br>";
}// end of loop
?>

 

Regards

Huggie

Sure i guess, the form is in 3 stages, (uploadForm1.php), (property_add_process_form.php) and (add_test.php)

The uploadForm1.php is included in property_add.php but that shouldnt matter should it?

 

This is the first form

 

<html>
<head>
<title># of Files to Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="property_add_process_form.php">
  <p>Enter the amount of images you have for your new property below. Max = 9.</p>
  <p>
    <input name="uploadNeed" type="text" id="uploadNeed" maxlength="1">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
</body>
</html>

 

This opens property_add_process_form.php.

 

The code in this page is

 

<?php require_once('../Connections/gcproperty.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "restricted.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
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_gcproperty, $gcproperty);
$query_Recordset1 = "SELECT * FROM employees";
$Recordset1 = mysql_query($query_Recordset1, $gcproperty) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>Administration Panel</title>

<style type="text/css">
<!--
.style1 {color: #000000}
body {
background-color: #000000;
}
.style2 {
color: #FFFFFF;
font-size: 10px;
}
-->
</style>

<link href="../css/admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style4 {font-size: 16px}
-->
</style>
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style7 {font-size: 18px}
.style8 {font-size: 10px}
-->
</style>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>


<body>
<div id="container"><table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="7"><img src="../images/admin-header.jpg" alt="GC Propery" width="780" height="223" /></td>
  </tr>
  <tr>
    <td width="149" height="24" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="edit_privacy.php" target="_self">Terms / Privacy</a></div></td>
    <td width="112" background="../images/navbar.jpg" class="name"><div align="center" class="admin"> <a href="property_add.php" target="_self">Property</a></div></td>
    <td width="113" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="news.php" target="_self">News</a></div></td>
    <td width="111" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="email.php" target="_self">email</a></div></td>
    <td width="113" background="../images/navbar.jpg" class="name"><div align="center" class="admin"> <a href="links.php" target="_self">Links</a></div></td>
    <td width="101" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="main.php" target="_self">Home</a></div></td>
    <td width="81" background="../images/navbar.jpg" class="name"><div align="center" class="admin"><a href="logout.php" target="_self" class="admin">Logout</a></div></td>
  </tr>
  <tr>
    <td height="2" colspan="7" background="../images/bar.jpg" class="admin"> </td>
  </tr>
  <tr>
    <td colspan="7" class="admin"><div align="left">
      <blockquote>
        <p class="style2"><br />
          <u><span class="style4">Edit GCProperty.</span></u><br />
          <br />
          <a href="property_delete.php" target="_self"><span class="admin">Click here to Delete Property</span></a></p>
      </blockquote>
    </div></td>
  </tr>
  <tr>
    <td colspan="7" class="admin"><div align="center"><br />
    </div></td>
  </tr>
  <tr>
    <td colspan="7" class="admin"><form action="add_test.php" method="post" enctype="multipart/form-data" onsubmit="MM_validateForm('name','','R','content','','R');return document.MM_returnValue">
      <div align="left"><br />
          <table width="507" border="0" align="center" bgcolor="#333333">
            <tr>
              <td colspan="3" align="left" valign="bottom" bgcolor="#999999"><span class="style7">Add Property</span></td>
            </tr>
            <tr>
              <td colspan="3">Add a property to GCPRoperty Database<hr /></td>
            </tr>
            <tr>
              <td width="251"><div align="right">Name:</div></td>
              <td width="26"> </td>
              <td width="216"><input name="name" type="text" id="name" /></td>
            </tr>
            <tr>
              <td><div align="right">Suburb:</div></td>
              <td> </td>
              <td><input name = "suburb" type="text" id="suburb" /></td>
            </tr>
            <tr>
              <td><div align="right">Price: </div></td>
              <td> </td>
              <td><input name = "price" type="text" id="price" /></td>
            </tr>
            <tr>
              <td colspan="3">
                <p> </p></td>
            </tr>
            <tr>
              <td valign="top"><div align="right">Photo(s)</div></td>
              <td> </td>
              <td><p>
                <?
  // start of dynamic form
  $uploadNeed = $_POST['uploadNeed'];
  for($x=0;$x<$uploadNeed;$x++){
  ?>
                <input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>" />
                <?
  // end of for loop
  }
  ?>
                <input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>" />
                </p>
                </td>
            </tr>
            <tr>
              <td><div align="right">Text</div></td>
              <td> </td>
              <td><label>
                <textarea name="content" cols="40" rows="10" id="content"></textarea>
              </label></td>
            </tr>
            <tr>
              <td> </td>
              <td> </td>
              <td><input type="submit" value="Add" /></td>
            </tr>
          </table>
          <p> </p>
      </div>
    </form>
    <br /><br /></td>
  </tr>
  
  <tr>
    <td colspan="5"> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>
<div align="center"><br />
    <br />
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

 

and finally the property_add_test.php we have been working on.

 

<?php

//This is the directory where images will be saved
$path = '../images/';

//This gets all the other information from the form
$name=$_POST['name'];
$suburb=$_POST['suburb'];
$price=$_POST['price'];
$content=$_POST['content'];
$uploadFile0=($_FILES['uploadFile0']['name']);
$uploadFile1=($_FILES['uploadFile1']['name']);
$uploadFile2=($_FILES['uploadFile2']['name']);
$uploadFile3=($_FILES['uploadFile3']['name']);
$uploadFile4=($_FILES['uploadFile4']['name']);
$uploadFile5=($_FILES['uploadFile5']['name']);
$uploadFile6=($_FILES['uploadFile6']['name']);
$uploadFile7=($_FILES['uploadFile7']['name']);
$uploadFile8=($_FILES['uploadFile8']['name']);

// Connects to your Database
mysql_connect("localhost", "root", "5050888202") or die(mysql_error()) ;
mysql_select_db("gcproperty") or die(mysql_error()) ;

// Check the extension is valid
if (preg_match('/\.(jpg|jpeg|gif|png)$/i', $_FILES['uploadFile'. $x]['name'])){

   //Writes the information to the database
   mysql_query("INSERT INTO `employees` VALUES ('$name', '$suburb', '$price', '$content', '$uploadFile0', '$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')") ;

   $uploadNeed = $_POST['uploadNeed'];
   // start for loop
   for($x=0;$x<$uploadNeed;$x++){
      $file_name = $_FILES['uploadFile'. $x]['name'];
      
      // strip file_name of slashes
      $file_name = stripslashes($file_name);
      $file_name = str_replace("'","",$file_name);
      $copy = move_uploaded_file($_FILES['uploadFile'. $x]['tmp_name'], $path . $file_name);
   }
}
else {
   // Add your error code here
   echo "Sorry, file must be of type .jpg .jpeg .gif or .png\n";
}

// check if successfully copied

if($copy){
   print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">";
}
else{
   echo "$file_name | could not be uploaded!<br>";
}// end of loop
?>

 

Huggie, where are you from?

I want to pay you for the work you have done for me!

You have been of extream assistance, thanks a ton.

 

I will have php work in the future and may (most likely) need some help, paid work of course!

If you are interested i would like to be able to contact you when i need some help now and then.

I am not being paid much for this site but id feel better if i gave you something.

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.