emediastudios Posted September 25, 2007 Share Posted September 25, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/ Share on other sites More sharing options...
HuggieBear Posted September 25, 2007 Share Posted September 25, 2007 Take a look at move_uploaded_file() Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-354834 Share on other sites More sharing options...
emediastudios Posted September 25, 2007 Author Share Posted September 25, 2007 Take a look at move_uploaded_file() Regards Huggie Im a newbe, still learning, i dont know how to do it, i read the link Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-354850 Share on other sites More sharing options...
HuggieBear Posted September 25, 2007 Share Posted September 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-354854 Share on other sites More sharing options...
emediastudios Posted September 26, 2007 Author Share Posted September 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-355574 Share on other sites More sharing options...
HuggieBear Posted September 26, 2007 Share Posted September 26, 2007 Firstly add a forward slash to the end of that path, so it reads $path = '../images/'; Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-355577 Share on other sites More sharing options...
HuggieBear Posted September 26, 2007 Share Posted September 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-355579 Share on other sites More sharing options...
emediastudios Posted September 26, 2007 Author Share Posted September 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-355584 Share on other sites More sharing options...
HuggieBear Posted September 26, 2007 Share Posted September 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-355591 Share on other sites More sharing options...
emediastudios Posted September 26, 2007 Author Share Posted September 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-355608 Share on other sites More sharing options...
HuggieBear Posted September 26, 2007 Share Posted September 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-355610 Share on other sites More sharing options...
emediastudios Posted September 27, 2007 Author Share Posted September 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-356235 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-356253 Share on other sites More sharing options...
emediastudios Posted September 27, 2007 Author Share Posted September 27, 2007 I added it as you had it, i cant upload any file now, i get the error Sorry, file must be of type .jpg .jpeg .gif or .png | could not be uploaded! ??? Thanks again huggie Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-356262 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 Can I suggest a more simple solution? It will require you to change your html form very slightly, can you do that? Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-356266 Share on other sites More sharing options...
emediastudios Posted September 27, 2007 Author Share Posted September 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-356287 Share on other sites More sharing options...
HuggieBear Posted September 27, 2007 Share Posted September 27, 2007 I'm based in the UK and I'll PM you from here on in... Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70616-solved-upload-file-directory-setting/#findComment-356292 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.