This code does not work properly. The code does execute but i am unable to see where the file should be uploaded to. I checked the default directory referenced by the php.ini file but to no avail.

<?php
$to = "nextphaze@live.com";
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$mobile = $_REQUEST['mobile'] ;
$email = $_REQUEST['email'] ;
$address = $_REQUEST['address'] ;
$city = $_REQUEST['city'] ;
$subject = "Student Submission Form From: $firstname";
$state = $_REQUEST['state'] ;
$zip = $_REQUEST['zip'] ;
$collegename = $_REQUEST['collegename'] ;
$collegestate = $_REQUEST['collegestate'] ;
$collegezip = $_REQUEST['collegezip'] ;
$collegestatus = $_REQUEST['collegestatus'] ;
$year = $_REQUEST['year'] ;
$message = $_REQUEST['message'] ;
$upload = $_REQUEST['upload'] ;
$headers = "From: [email]nextphaze@live.com[/email]\r\nReply-to: [email]nextphaze@live.com[/email]";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " . $from . "\r\n";
$body = "From: First Name: $firstname \n\n Last Name: $lastname \n\n Mobile Number: $mobile \n\n Email: $email \n\n Address: $address \n\n City: $city \n\n State: $state \n\n 
				Zip Code: $zip \n\n College Name: $collegename \n\n College State: $collegestate \n\n College Zip: $collegezip \n\n College Status: $collegestatus \n\n Year Graduated: $year \n\n Comments: $message \n\n File: $upload";
$sent = mail($to, $subject, $body, $headers) ;
	
if ($sent)
	echo "Mail has been successfully sent. We will contact you shortly.";

// ==============
// Configuration
// ==============
$uploaddir = "/file..aslhfld;a/";
// Where you want the files to upload to
//Important: Make sure this folders permissions is 0777!
$allowed_ext = "jpg, gif, png, pdf, psd, txt, bmp, mpeg, pjpeg, jpeg, doc, docx";
// These are the allowed extensions of the files that are uploaded
$max_size = "100000000";
// 50000 is the same as 50kb
$max_height = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images
$max_width = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images

// Check Entension
$filename = ($_FILES['upload']['name']);
$extension = pathinfo($_FILES['upload']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}

// Check File Size
if ($ok == "1") {
if($_FILES['upload']['size'] > $max_size)
{
print "File size is too big!";
exit;
}


// The Upload Part
if(is_uploaded_file($_FILES['upload']['name']))
{
move_uploaded_file($_FILES['upload']['name'],$uploaddir.'/$file/'.$_FILES['file']['name']);
}
print "Your file has been uploaded successfully!";
} else {
print "Incorrect file extension!";
}
?>

<p>Please click <a href="../forms/stuform.html">here</a> to return to the home page.</p>

SO I NEED HELP WITH THE ABOVE CODE. EVERYTHING WORKS FINE IN TERMS OF THE EMAIL, I NEED HELP WITH THE UPLOAD PART.

HERE IS THE THING THOUGH, THE FOLLOWING CODE IS PRETTY MUCH THE SAME EXCEPT WITHOUT THE OTHER CODING INVOLVED.

<?php
// ==============
// Configuration
// ==============
$uploaddir = "uploads/";
// Where you want the files to upload to
//Important: Make sure this folders permissions is 0777!
$allowed_ext = "jpg, gif, png, txt, pdf, bmp, psd, mpeg, pjpeg, jpeg, doc, docx";
// These are the allowed extensions of the files that are uploaded
$max_size = "100000000";
// 50000 is the same as 50kb
$max_height = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images
$max_width = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images

// Check Entension
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}

// Check File Size
if ($ok == "1") {
if($_FILES['file']['size'] > $max_size)
{
print "File size is too big!";
exit;
}

// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
{
print "File height and/or width are too big!";
exit;
}
}

// The Upload Part
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'uploads'.$_FILES['file']['name']);
}
print "Your file has been uploaded successfully!";
} else {
print "Incorrect file extension!";
}
?>

THE ABOVE CODE WORKS, AND I AM ABLE TO SEE WHERE THE FILE IS BEING UPLOADED AND IT IS NOT REFERENCED AT ALL BY THE DEFAULT IN THE PHP.INI. THE FUNNY THINGS IS THAT THIS PART OF THE CODE IS JUST ABOUT THE SAME AS THE PREVIOUS CODE MENTIONED ABOVE. I AM ASKING FOR DETAILED HELP. PLEASE DO NOT RESPOND IF YOU HAVE NOTHING SPECIFIC TO SAY OR HAVE EXTREMELY VAGUE DIRECTIONS. I NEED HELP WITH THE CODE AS SOON AS POSSIBLE. THANK YOU IN ADVANCE.

Ok... I'm going to try and help you out even though I'm not sure if my answer is not specific enough for you. I tried out your code and it worked fine. There is one thing I would like you to check.

Have you added in the enctype="multipart/form-data" in your form. This is required for the upload to work. The form tag should be

<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">

Also the uploads folder to which the files are being uploaded to should be on the same level as the upload program.

I do not see any other reason as to why the code should not work, other than the above.

If both these are correct then please let me know and I'll see how I can help you out further.

Hmmm... There is a minor difference in those codes. Let me explain..

This is your first code for uploading file...

move_uploaded_file($_FILES['upload']['name'],$uploaddir.'/$file/'.$_FILES['file']['name']);

And, this is your second code for uploading file...

move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'uploads'.$_FILES['file']['name']);

Now, can you feel the difference..?

Nothing, in the first code, you are uploading the file with reference of actual file name to the target path.. [ (i.e) $_FILES ]. This is wrong, because when you uploading your file, the file contents will be moved to a temporary file. So we have to refer the temporary file to upload to the target directory with its original name as of your second code [ (i.e) $_FILES, ]..

Hope you understand this, if still any probs, let me know..

i want to thank the both of you for replying. i will take all information and apply and notify of changes if any. again thank you so much.

berry

i want to thank the both of you for replying. i will take all information and apply and notify of changes if any. again thank you so much.

berry

ok, i have tried both of your methods and still to no avail. though dragonbaki, i think that you method has come the closest to a resolution. here are the changes that i have made. my problem now is that i do get a file upload but it is in a format not detailed in the variable extensions. the resulting code is below:

<?php
$to = "nextphaze@live.com";
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$mobile = $_REQUEST['mobile'] ;
$email = $_REQUEST['email'] ;
$address = $_REQUEST['address'] ;
$city = $_REQUEST['city'] ;
$subject = "Student Submission Form From: $firstname";
$state = $_REQUEST['state'] ;
$zip = $_REQUEST['zip'] ;
$collegename = $_REQUEST['collegename'] ;
$collegestate = $_REQUEST['collegestate'] ;
$collegezip = $_REQUEST['collegezip'] ;
$collegestatus = $_REQUEST['collegestatus'] ;
$year = $_REQUEST['year'] ;
$message = $_REQUEST['message'] ;
$upload = $_REQUEST['upload'] ;
$headers = "From: [email]nextphaze@live.com[/email]\r\nReply-to: [email]nextphaze@live.com[/email]";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " . $from . "\r\n";
$body = "From: First Name: $firstname \n\n Last Name: $lastname \n\n Mobile Number: $mobile \n\n Email: $email \n\n Address: $address \n\n City: $city \n\n State: $state \n\n 
				Zip Code: $zip \n\n College Name: $collegename \n\n College State: $collegestate \n\n College Zip: $collegezip \n\n College Status: $collegestatus \n\n Year Graduated: $year \n\n Comments: $message \n\n File: $upload";
$sent = mail($to, $subject, $body, $headers) ;
	
if ($sent)
	echo "Mail has been successfully sent. We will contact you shortly.";
?>
<?php
// ==============
// Configuration
// ==============
$uploaddir = "fileholder/";
// Where you want the files to upload to
//Important: Make sure this folders permissions is 0777!
$allowed_ext = "jpg, gif, png, txt, pdf, bmp, psd, mpeg, pjpeg, jpeg, doc, docx";
// These are the allowed extensions of the files that are uploaded
$max_size = "100000000";
// 50000 is the same as 50kb
$max_height = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images
$max_width = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images

// Check Entension
$extension = pathinfo($_FILES['upload']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}

// Check File Size
if ($ok == "1") {
if($_FILES['file']['size'] > $max_size)
{
print "File size is too big!";
exit;
}


// The Upload Part
if(is_uploaded_file($_FILES['upload']['tmp_name']))
{
move_uploaded_file($_FILES['upload']['tmp_name'],$uploaddir.'fileholder/'.$_FILES['file']['tmp_name']);
}
print "Your file has been uploaded successfully!";
} else {
print "Incorrect file extension!";
}
?>

<p>Please click <a href="../forms/stuform.html">here</a> to return to the home page.</p>

DRAGONBAKI, i applied the changes you suggested where you suggested that i do and i met with a "invalid extension" error. if you can look over the code and the changes where i made them, which is exactly where you suggested i just kept some parts of it as i did prior.

I WILL BREAKDOWN EVERYTHING THAT I DO (PLEASE DO NOT TAKE THE CAPS PERSONALLY, I AM NOT YELLING. THIS IS GOING TO BE A LONG REPLY AND I WANT TO DISTINGUISH ALL THAT I AM DOING. THANKS!)

WHERE THE CODE SAYS "MOVE_UPLOADED_FILE($_FILES" ANY TIME I CHANGE THESE STRING I MAY OR MAY NOT SEE A CHANGE. WITH THE CURRENT CODE WHEN I LOOK INTO THE PARTICULAR FILE THAT I WANT THE UPLOADED FILE TO BE I GET THE FILE NAME, THE TIME THAT IT WAS UPLOADED AND WHAT TYPE OF FILE IT WAS.

SO NOW THAT WHOLE LINE OF CODE:

"move_uploaded_file("$_FILES,$uploaddir.'/fileholder/'.$_FILES); WHEN I KEEP THE CODE LIKE THIS, THE FILE IS UPLOADED BUT AS SAID BEFORE IN A FORMAT THAT I CANNOT OPEN. I SEE THIS AS PROGRESS BUT NOW NEED ANSWERS AS TO WHY THE FILE IS BEING UPLOADED IN AN INACCESSIBLE FORMAT. YOUR HELP WOULD GREATLY BE APPRECIATE. THANKS.

BERRY

What is in your line 19...

$extension = $extension[extension];

R u getting file extension.. This is no need..

$file=$_FILES;

If you are doing like this, it will automatically get your file name with extension. Do upload directly.. and still you did not replace the code at line 39..

move_uploaded_file($_FILES,$uploaddir.'fileholder/'.$_FILES);

If you want to check the valid extensions means, try this...

<?php

$file_name=$_FILES['upload']['name'];
$ext=explode(".",$file_name);
$a=count($ext)-1;
$extension=$ext[$a];

// Now this is having your file extension ($extension). Check as usual for valid files..

?>

Hi, I was finally able to get the code to work.

Here are the changes made:

<?php
// ==============
// Configuration
// ==============
$uploaddir = "name/";
// Where you want the files to upload to
//Important: Make sure this folders permissions is 0777!
$allowed_ext = "jpg, gif, png, txt, pdf, bmp, psd, mpeg, pjpeg, jpeg, doc, docx";
// These are the allowed extensions of the files that are uploaded
$max_size = "100000000";
// 50000 is the same as 50kb
$max_height = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images
$max_width = "13680";
// This is in pixels - Leave this field empty if you don't want to upload images

// Check Entension
$extension = pathinfo($_FILES['upload']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}

// Check File Size
if ($ok == "1") {
if($_FILES['upload']['size'] > $max_size)
{
print "File size is too big!";
exit;
}


// The Upload Part
if (move_uploaded_file($_FILES['upload']['tmp_name'],$uploaddir.'name'.$_FILES['upload']['name']));

print "Your file has been uploaded successfully!";
} else {
print "Incorrect file extension!";
}
?>

<p>Please click <a href="../forms/stuform.html">here</a> to return to the home page.</p>.

In the original code, lines 37 and 38 have been erased. The file is uploaded to the folder intended. Here is my problem however now. The email is received, no error messages are recorded but once i check the email, their is no indication of an attachment being sent along with the email. How do i rectify this?

Dragonbaki, when i "erase $extension = $extension[extension];" i get a "incorrect file extension error". So to avoid a headache, i just keep it.

This site is informative and though my activity is not that much at previous times past i will certainly be using it now far more frequently! I would like to thank the programmers who helped me the last time. I hope that they are still apart of the community

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.