Jump to content

Message Text Doesn't Arrive in Upload File Form


Chrisj
 Share

Recommended Posts

I have this Upload Form that uploads a file successfully,
and sends the info from the Name-form-field and the Email-form-field successfully.
But nothing arrives from the Message-form-field. Here's the code:
 
<?php
session_start();
require_once 'phps3integration_lib.php';
$message = "";
$message1= "";
if (@$_POST['submit'] != "") {
$allowed_ext = array("gif", "jpeg", "jpg", "png", "pdf", "doc", "docs", "zip", "mov", "MOV", "flv", "mp4", "3gp", "3GP");
$extension = end(explode(".", $_FILES["file"]["name"]));
if (($_FILES["file"]["size"] < 104857600) && in_array($extension, $allowed_ext)) {
if ($_FILES["file"]["error"] > 0) {
//$message.="There is some error in upload, see: " . $_FILES["file"]["error"] . "<br>";//Enable this to see actual error
$message.="There is some error in upload. Please try after some time.";
} else {
$uploaddir = '../Upload/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
$uploaded_file = false;
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
$uploaded_file = $_FILES['file']['name'];
}
 if ($uploaded_file != FALSE) {
$user_name = @$_POST['user_name'] != "" ? @$_POST['user_name'] : "Anonymous";
$form_data = array(
'file' => $uploaded_file,
'user_name' => $user_name,
'type' => 'file'
);

if(empty($_POST['agree']) || $_POST['agree'] != 'agree') {
$message1.= "Please read and agree to the Terms and Conditions To Proceed With Upload";
};

mysql_query("INSERT INTO `phps3files` (`id`, `file`, `user_name`, `type`) VALUES (NULL, '" . $uploaded_file . "', '" . $user_name . "', 'file')") or die(mysql_error());
$message.= "File Successfully Uploaded";
} else {
$message.="There is some error in upload. Please try after some time.";
}
}
} else {
$message.= "Invalid file, Please upload a gif/jpeg/jpg/png/pdf/doc/docs/zip/mov/flv/mp4/3gp file of maximum size 25 MB.";
}
}

 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $email_to = "someone@somewhere.com";
	    $email_subject = "From FORM";
	    $message = $_POST['message'];
	    $name = $_POST['name'];
	    $email = $_POST['email'];

	$headers = "From: $email \r\n";
    $sent = mail($email_to,$email_subject,$message,$headers);
}


?>

<?php
require_once 'header.php';
?>
<head>

<script>
var ids = ['input', 'message', 'button'];
var obj = {};

ids.forEach(function (v) {
    obj[v] = document.getElementById(v);
});

obj.input.style.display = 'none';
obj.button.style.display = 'block';

obj.input.addEventListener('change', function () {
    obj.message.innerText = this.value;
    obj.message.style.display = 'block';
});

obj.button.addEventListener('click', function (e) {
    e.preventDefault();

    obj.input.click();
});
</script>

</head>
<html>
<div id="genericUp">
<br /><br /><br /><br />
<font size="6" color="#84786e"><b>Upload</b></font><br /><br />

<fieldset>
<form action="" method="post" enctype="multipart/form-data" onsubmit="if(document.getElementById('agree').checked) { return true; } else { alert('Please indicate that you have read and agree to the Terms by selecting the checkbox'); return false; }">

<div class="control-group">
<label for="file" class="control-label"><font size="6" color="#454545"><b>Choose a file to upload:</b></font></label><br /><br />

<!--<div class='controls'>-->
<input id="input" name="file" type="file" /></input>
<button id="button"><font size="3" color="#454545">Click To<br /> Select File</font></button>
<div id="message"><font size="3" color="#454545">No File Chosen</font></div>
</div>
<div>
<br />
<input class="form-control" type="text" name="name" maxlength="50" style="width:250px; height:20px; background-color:transparent; float:left; padding:0px 0px 0px 10px; margin:0px 0px 5px 0px; font-family: helvetica;
font-size: 12px; color:#cccccc; border:1px solid #cccccc"; placeholder="Name">
<br /><br />
</div>
<div>
<input class="form-control" type="text" name="email" maxlength="50" style="width:250px; height:20px; background-color:transparent; float:left; padding:0px 0px 0px 10px; margin:0px 0px 5px 0px; font-family: helvetica;
font-size: 12px; color:#cccccc; border:1px solid #cccccc"; placeholder="Email">
<br /><br />
</div>
<textarea id="message4"  name="message" maxlength="70" cols="25" rows="6"></textarea>
<br /><br />
</div>
<div>
<input type="checkbox" name="checkbox" value="check" id="agree" vertical-align:top;/> By uploading a file you agree to these
<a href="../Terms.php" target="_blank"><font size="2" color="#000000" face="Arial"><u>Upload Terms/Agreement</u></a></font></label>
</div>

<br />
<div class="control-group">
<div class='controls'>
<label class="myLabel1">
<input type="submit" name="submit" value="Submit" class="btn" style="opacity: 0"><br /><br />
</label><br /><br />
</div>
</form>
</fieldset>

<script>
var ids = ['input', 'message', 'button'];
var obj = {};

ids.forEach(function (v) {
    obj[v] = document.getElementById(v);
});

obj.input.style.display = 'none';
obj.button.style.display = 'inline-block';

obj.input.addEventListener('change', function () {
    var filename = this.value.replace(/^.*[\\\/]/, '');
		obj.message.innerHTML  = filename;
    obj.message.style.display = 'inline-block';
});

obj.button.addEventListener('click', function (e) {
    e.preventDefault();

    obj.input.click();
});
</script>
<?php
if ($message != "" || @$_SESSION['message'] != "") {
    ?>
    <div class="alert alert-success">
    <?php echo $message; ?>     
    <?php
    echo @$_SESSION['message'];
    @$_SESSION['message'] = '';
    ?>
    </div>
    <?php
}
?>
<div>
</div>
</div>

Any help with getting what is entered into the Message field to be sent/delivered will be appreciated.

 

Link to comment
Share on other sites

Could it be the JS putting filename in the message field?

 

Your code is outdated. HTML font tags are long-ago deprecated. The HTML tag is in the wrong place.

 

There are much better ways of combining the html with php vars than going in and out and into PHP mode. Very tedious to type and much more so to read back. Look up the heredocs command in the manual.

 

And - stop using the @ operator to suppress warnings. If you wrote your code properly it wouldn't be necessary. It's better to KNOW what may be wrong than to ignore it. Setting conditions in your code that rely on things that aren't set is not a good way to program. IMHO.

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.