Skip to content

Commit f485bec

Browse files
authored
Create formpost.php
The form interpreter
1 parent 803c274 commit f485bec

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

formpost.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
// getting the POST from the form
3+
4+
if (isset($_POST['add_account'])) {
5+
if ($_POST['fields']) {
6+
foreach( $_POST['fields'] as $key=>$fieldArray ) {
7+
8+
if (!empty($_FILES)) {
9+
10+
$uploaddir = 'upload/'; // Upload directory
11+
12+
if (!is_dir($uploaddir)) // Check if upload directory exist
13+
{
14+
mkdir($uploaddir); // If no upload directory exist, create it
15+
}
16+
17+
$newname = time(); // Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT), to use it as part of the name
18+
$random = rand(100,999); // Getting some random numbers to add in the file names, to avoid files with the same name
19+
20+
$name = $newname.'-'.$random.'-'.$_FILES['fields']['name'][$key]['file_uploaded'][0]; // File Name Construction
21+
22+
$tempFile = $_FILES['fields']['tmp_name'][$key]['file_uploaded'][0]; // Getting temporary file location and temporary name ( e.g. /tmp/random_string__here )
23+
24+
$uploadfile = $uploaddir . $name; // Concatenating upload dir name with the file name
25+
26+
if (move_uploaded_file($tempFile, $uploadfile)) { // If file moved from temp to upload location with the name we constructed above
27+
echo 'File uploaded to '.$uploadfile.'.<br />';
28+
} else {
29+
echo 'File not uploaded!<br />';
30+
}
31+
32+
}
33+
34+
$keys = array_keys($fieldArray);
35+
$values = array_map("mysql_real_escape_string",$fieldArray);
36+
$q = "INSERT INTO accounts (".implode(',',$keys).", file_uploaded) VALUES ('".implode('\',\'',$values)."', ".$uploadfile." )";
37+
$r = mysql_query($q, $dbc );
38+
39+
}
40+
}
41+
echo "<i><h2><strong>" . count($_POST['fields']) . "</strong> Account(s) Added</h2></i>";
42+
}
43+
?>

0 commit comments

Comments
 (0)