Unfortunitly my Patentience had run out and I learned if else statements... and I wrote a little validation process but I need some help...
What happens is even though all the input are valid the upload form does not show if someone could just help me with that, it would be fantastic THANKS!PHP Code:<html>
<body>
<?php
$input2 = $_POST["Name"];
$input3 = $_POST["Email"];
$input4 = $_POST["time"];
$input5 = $_POST["TermsOfService"];
$input6 = $_POST["3p42r3ad3a4than32"];
$input7 = $_POST["Title"];
$input8 = $_POST["Description"];
$input9 = $_POST["file1"];
$input10 = $_POST["file2"];
$empty = '';
$agree = 'Agreed';
$a = '329r8g';
?>
<?php
$c = '1';
$d = '0';
$valid = '5';
if ($empty == $input2) {
echo "Your Name cannot be blank.<br>";
} else {
++$d;
}
if ($empty == $input3) {
echo "Your EmailAddress cannot be blank.<br>";
} else {
++$d;
}
if ($empty == $input4) {
echo "Make sure your clock is set to the correct date, we record dates so we can know exactly when you submitted your files...<br>";
} else {
++$d;
}
if ($empty == $input5) {
echo "You must agree to the Terms Of Service.<br>";
} else {
++$d;
}
if ($empty == $input6) {
echo "There is an error with our form we are sorry for this problem we will fix it tomorrow.<br>";
} else {
++$d;
}
if ($d == $valid){
$upload_dir = "submitions/";
$num_files = 2;
//the file size in bytes.
$size_bytes =20480000; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg");
//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload.");
}
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem.");
}
//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){
echo "<h3>Upload results:</h3>";
//do a loop for uploading files based on ($num_files) number of files.
for ($i = 1; $i <= $num_files; $i++) {
//define variables to hold the values.
$new_file = $_FILES['file'.$i];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];
#-----------------------------------------------------------#
# this code will check if the files was selected or not. #
#-----------------------------------------------------------#
if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "File $i: Not selected.<br>";
}else{
$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "File $i: ($file_name) Wrong file extension. <br>";
}else{
if ($file_size > $size_bytes){
echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";
}else{
if(file_exists($upload_dir.$file_name)){
echo "File $i: ($file_name) already exists.<br>";
}else{
if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "File $i: ($file_name) Uploaded.<br>";
}else{
echo "File $i: Faild to upload.<br>";
}#end of (move_uploaded_file).
}#end of (file_exists).
}#end of (file_size).
}#end of (limitedext).
}#end of (!is_uploaded_file).
}#end of (for loop).
# print back button.
echo "»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
echo " <h3>Select files to upload!.</h3>
Max file size = ". $size_bytes / 1024 ." KB";
echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
// show the file input field based on($num_files).
for ($i = 1; $i <= $num_files; $i++) {
echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
}
echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
<input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
</form>";
}
$data = "<table border='1'>
<tr><td>User IP Address:</td><td>$input1</td></tr>
<tr><td>Name:</td><td>$input2</td></tr>
<tr><td>Email Address:<td>$input3</td></tr>
<tr><td>Date Submitted:</td><td>$input4</td></tr>
<tr><td>Description</td><td><textarea cols='50' rows='5'>$input6</textarea></td></tr>
<tr><td>File 1 Location:</td><td>$file1</td></tr>
<tr><td>File 2 Location:</td><td>$file2</td></tr></table>";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file";
exit;
}
echo "Success your information has been submitted! Now please submit your files...";
fclose($handle);
}
} else{
echo "You must fill out all fields properly";
}
