PHP Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rosshodges
Forum Newbie
Posts: 1
Joined: Tue Feb 03, 2004 11:35 am

PHP Variables

Post by rosshodges »

Help! I have this code, it uploads as it should and it sends the email, what it doesnt do is send the variables in the email so the email is blank ive tried everything to fix i but i cant if anyone can help id be most greatfull! Regards, Ross

<html>
<form enctype="multipart/form-data" action="upload.php" method="post">

<p> Address:
<input type=text name=address>
<br>
Email:
<input type=text name=email>
<br>
name
<input type=text name=mainname>
</p>
<p>File
<input name="userfile" type="file" />
<input name="submit" type="submit" value="Send File" />
</p>
</form>
</html>



php:

Code: Select all

<?php


srand(time()); 
$random1 = (rand()%99999); 
$random2 = (rand()%99999); 
$random3 = $random1 . $random2; 
$file = $_FILES['userfile']['name']; 
$content = $mainname; 
$content.= "Address: " .$address; 
$content.= "Email: " .$emailaddress; 
$content.= "ID thingy: " .$file; 



set_time_limit(3000); 

$uploaddir = 'C:\\inetpub\\clients\\awt969\''; 
$uploadfile = $uploaddir . $random3 . $_FILES['userfile']['name']; 

print "<pre>"; 
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
   print "Done"; 
mail("me@me.com", "Title", $content); 
} 
else { 
   Print "There was an whilst uploading" . $file . "<br>Please email the file to me@me.com"; 

} 

?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Since PHP v 4.2.0, register_globals has defaulted to OFF in the PHP.ini. What this basically means is that things in forms are no longer globals. Instead they are passed by use of the $_POST or $_GET superglobal array. If you don't understand that its OK, just know that when using a form (with method="post") you have to do this instead:

Code: Select all

<?php
$content = $_POST['mainname'];
$content.= "Address: " .$_POST['address'];
$content.= "Email: " .$_POST['emailaddress'];
$content.= "ID thingy: " .$_POST['file']; 
?>
I see that you are already using the $_FILES superglobal. ($_FILES['userfile']['name']) :D
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

I think we should make the register_globals sticky thread maybe four times as large as it is now? Maybe it could blink and bounce back and forth? Dance a little can-can or something?
Post Reply