Page 1 of 1

PHP Variables

Posted: Tue Feb 03, 2004 11:35 am
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"; 

} 

?>

Posted: Tue Feb 03, 2004 2:41 pm
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

Posted: Tue Feb 03, 2004 7:11 pm
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?