"; $lines = file("posts.txt"); $posted_array = array(); foreach ($lines as $key => $line) { $posted_array[$key] = $line; $words = explode("|", $line); $each_posted_array = array(); foreach ($words as $key => $word) { $word = trim($word); $each_posted_array[$key] = $word; if( count($each_posted_array) != 7 ) { echo "invalid input only.
"; $get_file_invalid = true; break; } if($get_file_invalid) { break; } } // inside foreach if($get_file_invalid) { break; } } // outside foreach } // FALSE } // if (!isset($_POST['submit'])) if ( count($_GET) > 0 ) { if (file_exists("posts.txt") === FALSE) { echo "posts.txt doesn't exist."; } else { echo "get request here with a file named posts.txt.

"; } // if (file_exists("posts.txt") === FALSE) } elseif ( count($_POST) > 0 ) // if ( count($_GET) > 0 ) { /* if ($_SERVER["REQUEST_METHOD"] == "POST") { foreach ($_SERVER as $key => $value) { echo '$_SERVER['.$key.'] = '.$value."
"; } } */ if($_FILES['file']['error'] === 4) { $message = '
Please select a jpg file.!
'; } elseif(!checkInput($_POST)) { $message = '
All inputs are required!
'; } else // if(!checkInput($_POST)) { if(mime_content_type($_FILES['file']['tmp_name']) == 'image/jpeg') { $new_filename = time() . "_" . $_FILES['file']['name']; move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $new_filename); // validation here with regex if(!checkValidation($_POST)) { $message = '
Regex Validation Fail!
'; } else { $fp = fopen("posts.txt", "a+"); fwrite($fp, trim(ucwords(strtolower($_POST['firstName']))) . '|' . trim(ucwords(strtolower($_POST['lastName']))) . '|' . trim(ucwords(strtolower($_POST['title']))) . '|' . trim($_POST['comment']) . '|' . trim($_POST['priority']) . '|' . $new_filename . '|' . time() . PHP_EOL); fclose($fp); } } // if(mime_content_type($_FILES['file']['tmp_name']) == 'image/jpeg') else { echo "The file type is wrong."; }// if(mime_content_type($_FILES['file']['tmp_name']) == 'image/jpeg') } // if(!checkInput($_POST)) } // elseif ( count($_POST) > 0 ) ?> COMP 3015
Search
$line) { $posted_array[$key] = $line; // $priority[$key] = $line['priority']; // echo '$posted_array['.$key.'] = '.$line; // echo '$priority['.$key.'] = '.$line['priority']; $words = explode("|", $line); $each_posted_array = array(); foreach ($words as $key => $word) { $word = trim($word); $each_posted_array[$key] = $word; if($key == 4) { if($each_posted_array[4] == 1) { $key_priority = 1; } elseif($each_posted_array[4] == 2) { $key_priority = 2; } elseif($each_posted_array[4] == 3) { $key_priority = 3; } else { $key_priority = 3; } } // if($key == 4) ////// echo '$each_posted_array[' . $key . '] = ' . $word; // echo $word; } if( count($each_posted_array) == 7 ) { if($key_priority == 1) { // echo "
word1 is: " . $word . "
"; $priority1 = array(0 => $each_posted_array[0], 1 => $each_posted_array[1], 2 => $each_posted_array[2], 3 => $each_posted_array[3], 4 => $each_posted_array[4], 5 => $each_posted_array[5], 6 => $each_posted_array[6] ); // $array_merged = array_merge($each_posted_array, $priority1); // array_push($priority1, $priority1_1); // foreach ($array_merged as $key => $value) { // echo '
array_merged $array_merged['.$key.'] = '.$value. "
"; // echo "
push_array(): " . $value . "
"; // } for ($i=0; $i < 7; $i++) { $priority1[$i] = $each_posted_array[$i]; // array_push($priority1, $each_posted_array[$i]); // $priority3[$i] = $each_posted_array[$i];; } /* $priority1[0] = $each_posted_array[0]; $priority1[1] = $each_posted_array[1]; $priority1[2] = $each_posted_array[2]; $priority1[3] = $each_posted_array[3]; $priority1[4] = $each_posted_array[4]; $priority1[5] = $each_posted_array[5]; $priority1[6] = $each_posted_array[6]; */ } elseif($key_priority == 2) { // echo "
word2 is: " . $word . "
"; $priority2[0] = $each_posted_array[0]; $priority2[1] = $each_posted_array[1]; $priority2[2] = $each_posted_array[2]; $priority2[3] = $each_posted_array[3]; $priority2[4] = $each_posted_array[4]; $priority2[5] = $each_posted_array[5]; $priority2[6] = $each_posted_array[6]; } elseif($key_priority == 3) { // echo "
word3 is: " . $word . "
"; $priority3[0] = $each_posted_array[0]; $priority3[1] = $each_posted_array[1]; $priority3[2] = $each_posted_array[2]; $priority3[3] = $each_posted_array[3]; $priority3[4] = $each_posted_array[4]; $priority3[5] = $each_posted_array[5]; $priority3[6] = $each_posted_array[6]; } else { for ($i=0; $i < 7; $i++) { // array_push($priority3[$i], $each_posted_array[$i]); // $priority3[$i] = $each_posted_array[$i];; } } // if($key_priority == 1) ?>
">

Posted on

$line) { // outside foreach /* foreach ($priority1 as $key => $value) { echo '
THERE $priority1['.$key.'] = '.$value. "
"; // echo "
push_array(): " . $value . "
"; } */ ?>