Click to See Complete Forum and Search --> : Combining PHP?
MYShvartsman
02-20-2006, 11:40 AM
I would like to know how to complete one of two things. Either have a submit button work with two .php files. Or how to combine the following:
<?PHP
$to = "a@x.com";
$subject = "From form";
$headers = "From: Form Mailer";
$forward = 1;
$location = "random.com";
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "Below is the result of a request from random.com. It was submitted on $date at $time.\n\n";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting your request!";
}
?>
with the following:
<?php
$uploaddir = "uploads";
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
print "Upload Completed!";
?>
any help would be greatly apperciated.
NogDog
02-20-2006, 11:52 AM
Off hand, I can't see any reason why you couldn't just cut-and-paste the code from one into the other.
MYShvartsman
02-20-2006, 12:02 PM
I attempted that but what ended up happening is it would send me an e-mail from the "file" field it would send: C:/documents.... etc :)
MYShvartsman
02-20-2006, 12:29 PM
This is my attempt at combining the code. PHP is not something I am strong in so be nice :)
<?php
$uploaddir = "uploads";
$to = "myshvartsman@gmail.com";
$subject = "Custom USB Request from form";
$headers = "From: Form Mailer";
$forward = 1;
$location = "http://exile.atherra.net/Upload Test/";
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "Below is the result of a request from Atherra. It was submitted on $date at $time.\n\n";
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting your request!";
}
?>
Results in an e-mail of:
Name : test
EMail : test
Phone : test
Style : NY Style
Quantity : TEST
Comments : test
File : C:\\Documents and Settings\...\Chart.jpg
Submit : Submit
This is the page where I'm testing this http://exile.atherra.net/Upload%20Test/
Mester Pediz
02-20-2006, 01:00 PM
Dunno if i'm missing something... but what exactly are you trying to do?
Upload a file and send a mail about it has been uploaded?! or do you just want a mail and upload possibillity in the same .php doc? (coulden't see the reason for the last but....)
Cuz if you want the two things to work seperatly, then all you need to do is put them into a switch() statement, then you can change between them.
I would though still advice that you keep it in two seperate files to avoid too many problems
ShrineDesigns
02-20-2006, 03:33 PM
do you mean have the one php script server the html form and parse the form data
it can be easy or very difficult depending on steps are involved (handling multiple forms)
example (probably not the best example lol)<?php
$error = array();
$done = false;
if($_POST)
{
// process post data...
if(!isset($_POST['foo']) && $_POST['foo'] != 'bar')
{
$error[] = 'foo is not bar';
}
if(empty($error))
{
$done = true;
}
else
{
$error = implode("<br>\n", $error);
$done = false;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html401/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
</head>
<body>
<?php if(!$done){
if(!empty($error)){ ?>
<div><?php echo $error; ?></div>
<?php } ?>
<form action="" method="post">
<div><input name="foo" type="text" value="bar"></div>
<div><button type="submit">Submit</button></div>
</form>
<?php }else{ ?>
<p>done!</p>
<?php } ?>
</body>
</html>
MYShvartsman
02-20-2006, 04:20 PM
What I want to do is when the Customer clicks the submit button for it to upload the file they selected to a folder on the server (which is what the upload.php file does), and send the rest of the form to my e-mail (which is what the mailer.php does).. (in this case the folder is "http://exile.atherra.net/Upload%20Test/uploads")
MYShvartsman
02-21-2006, 09:43 AM
anyone have any ideas?