/    Sign up×
Community /Pin to ProfileBookmark

Upload form

I’m using this php code for an upload form :

[code=php]<?php
include(“global.inc.php”);

$errors=0;
$error=”The following errors occured while processing your form input.<ul>”;
$Upload=$HTTP_POST_FILES[‘Upload’];
if($HTTP_POST_FILES[‘Upload’][‘tmp_name’]==””){ }
else if(!is_uploaded_file($HTTP_POST_FILES[‘Upload’][‘tmp_name’])){
$error.=”<li>The file, “.$HTTP_POST_FILES[‘Upload’][‘name’].”, was not uploaded!”;
$errors=1;
}
if($errors==1) echo $error;
else{
$image_part = date(“h_i_s”).”_”.$HTTP_POST_FILES[‘Upload’][‘name’];
$image_list[0] = $image_part;
copy($HTTP_POST_FILES[‘Upload’][‘tmp_name’], “files/”.$image_part);
$where_form_is=”http”.($HTTP_SERVER_VARS[“HTTPS”]==”on”?”s”:””).”://”.$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),”/”));
$message=”Upload: “.$where_form_is.”/files/”.$image_list[0].”
“;
$message = stripslashes($message);
mail(“[email protected]”,”Avatar Upload”,$message,”From: [email protected]”);
$make=fopen(“admin/data.dat”,”a”);
$to_put=””;
$to_put .= $where_form_is.”/files/”.$image_list[0].”
“;
fwrite($make,$to_put);

header(“Refresh: 0;url=http://www.hp-ships.com/thanks.html”);
?><?php
}
?>[/code]

Which works fine. It sends an email with the file, however I need to be sent the other 4 pieces of information in the form.

Is there any way of intergrating the following code with the upload code?

[code=php]$message = “Name: {$_POST[‘name’]}n”;
$message .= “Email = {$_POST[’email’]}n”;
$message .= “Sship: {$_POST[‘pship’]}n”;
$message .= “Sship2: {$_POST[‘pship2’]}n”;
[/code]

Otherwise, how do I configure my upload script so it also sends name, email, pship and pship2 as well as the file?

Any suggestions would be much appreciated.
?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@polorboyFeb 12.2007 — I have had a problem with using direct $_POST variables in my mail scripts in the past. It looks like your mail script should be sending you the information. Try storing the $_POST variables into another variable you define. Like

[code=php]
$var1 = $_POST['name'];
$var2 = $_POST['email'];
$var3 = $_POST['pship'];
$var4 = $_POST['pship'];

$message = "Name: {$var1}n";
$message .= "Email = {$var2}n";
$message .= "Sship: {$var3}n";
$message .= "Sship2: {$var4}n";
[/code]


This:
[code=php]
mail("[email protected]","Avatar Upload",$message,"From: [email protected]");
[/code]

should be sending you the info (if you are storing your info into the $_POST before you send the e-mail), and all the info from the $_POST is being stored in the $message variable.

For some reason when I do something like that my info gets sent via my e-mail (or similar scripts) no problem, but when I try to put in any $_POST or any superglobal variable into a script like that it will not go.

I am also seeing a few other things that might cause you some problems.

this:
[code=php]
$message = stripslashes($message);
[/code]

might not be working correctly. I can only talk from my experience, but what I would do is change that to something like:
[code=php]
$stpmessage = stripslashed($message);
[/code]

and store your newly modified message into a new variable.

So, the changes I would make would be:
[code=php]
<?php
include("global.inc.php");

$errors=0;
$error="The following errors occured while processing your form input.<ul>";
$Upload=$HTTP_POST_FILES['Upload'];
if($HTTP_POST_FILES['Upload']['tmp_name']==""){ }
else if(!is_uploaded_file($HTTP_POST_FILES['Upload']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['Upload']['name'].", was not uploaded!";
$errors=1;
}
if($errors==1) echo $error;
else{
$image_part = date("h_i_s")."_".$HTTP_POST_FILES['Upload']['name'];
$image_list[0] = $image_part;
copy($HTTP_POST_FILES['Upload']['tmp_name'], "files/".$image_part);
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Upload: ".$where_form_is."/files/".$image_list[0]."";

//and add this here so that your $message variable gets all the info it needs
$var1 = $_POST['name'];
$var2 = $_POST['email'];
$var3 = $_POST['pship'];
$var4 = $_POST['pship'];

$message .= "Name: {$var1}n";
$message .= "Email = {$var2}n";
$message .= "Sship: {$var3}n";
$message .= "Sship2: {$var4}n";

//Changed this so a new variable is getting the new info
$stpmessage = stripslashes($message);


mail("[email protected]","Avatar Upload",$stpmessage,"From: [email protected]");
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $where_form_is."/files/".$image_list[0]."
";
fwrite($make,$to_put);

header("Refresh: 0;url=http://www.hp-ships.com/thanks.html");
?><?php
}
?>
[/code]


That should allow you to do what you want and also fix a few things that might cause some issues. Hope that helps.
Copy linkTweet thisAlerts:
@LyssauthorFeb 13.2007 — I tried the code you gave but it came back saying:

Parse error: syntax error, unexpected T_VARIABLE in /home/lyss19/public_html/formgenerator/use/Upload/process.php on line 27
Copy linkTweet thisAlerts:
@NightShift58Feb 13.2007 — Unless you have a typo in your code, there's nothing in the code that should generate such an error. The code is a bit difficult to read nd as I was checking it, I did some moving around to get a grasp on it. Take a look, you may find it easier to work with:[code=php]<?php
include("global.inc.php");

$error = "";
$Upload = $HTTP_POST_FILES['Upload'];
if ($HTTP_POST_FILES['Upload']['tmp_name'] <> ""){
if(!is_uploaded_file($HTTP_POST_FILES['Upload']['tmp_name'])){
$error .= "<li>The file, " . $HTTP_POST_FILES['Upload']['name'] . ", was not uploaded!</li>";
}
}

if ($error <> "") {
echo "The following errors occured while processing your form input.<ul>$error</ul>";
} else {
$image_part = date("h_i_s") . "_" . $HTTP_POST_FILES['Upload']['name'];
$image_list[0] = $image_part;
copy($HTTP_POST_FILES['Upload']['tmp_name'], "files/".$image_part);
$where_form_is = "http" . ($HTTP_SERVER_VARS["HTTPS"]=="on" ? "s" : "") . "://" . $SERVER_NAME . strrev(strstr(strrev($PHP_SELF),"/"));
$message = "Upload: " . $where_form_is . "/files/" . $image_list[0] . "n";

$message .= "Name: " . $_POST['name'] . "n";
$message .= "Email: " . $_POST['email'] . "n";
$message .= "Sship: " . $_POST['pship'] . "n";
$message .= "Sship2: " . $_POST['pship'] . "n"; // Correct ???

mail("[email protected]","Avatar Upload",stripslashes($message),"From: [email protected]");
if ($make = fopen("admin/data.dat","a")) {
fwrite($make,$where_form_is."/files/".$image_list[0]."n";
fclose($make);
} else {
echo "Error writing to file.";
exit;
}
header("Location: http://www.hp-ships.com/thanks.html");
}
?>[/code]
Copy linkTweet thisAlerts:
@LyssauthorFeb 13.2007 — Thanks ? it's working now.
Copy linkTweet thisAlerts:
@NightShift58Feb 13.2007 — But double-check... You've got a variable (pship) being used twice. Is that correct?
Copy linkTweet thisAlerts:
@LyssauthorFeb 13.2007 — pship and pship2, yeah thats correct ?
×

Success!

Help @Lyss spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...