Solved

Email a file attachment from <input type=file> problem...

Posted on 2003-11-22
6
466 Views
Last Modified: 2006-11-17
When submitting a form that contains <input type="file" name="test"> to a php script, I get an undefined index trying to retrieve the value of "test".

I don't need to upload the file to the server, I just need the path on the users computer, because when they submit the form, I'll email the file in an attachment.

How do I access the "test" value in the script?  All the other submitted values work fine.

Thanks.

Scott.
0
Comment
Question by:kbach
  • 2
  • 2
  • 2
6 Comments
 
LVL 2

Expert Comment

by:HeadAcheMike
ID: 9805566
$test = $_POST['test'];

should work fine presuming that the forms method is POST
0
 
LVL 1

Author Comment

by:kbach
ID: 9806008
No,

Not for <input type=file>

I've discovered that you have to use $_FILES['test']['name'] to retrieve the name of the input file.  Which is now working.  Unfortunately, I have another problem.  All of the variables now post fine on my local machine, but when I upload them to the server (which is using PHP 4.0.6) none of the variables POST through.  They are all zero-length strings.

Has anyone encountered this problem?

Thanks.
0
 
LVL 2

Expert Comment

by:HeadAcheMike
ID: 9806100
>> Not for <input type=file>

I tried this on my server and it works fine, it prints the file name

<?php
if (isset($_POST['submit'])) {
echo $_POST['file'];
}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
<input type="file" name="file">
<input type="submit" name="submit">

anyway, for what you want to do i think youd benefit looking here:

http://www.php.net/manual/en/features.file-upload.php
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 13

Accepted Solution

by:
lozloz earned 200 total points
ID: 9806382
if you're using PHP 4.0.6 you need to use $HTTP_POST_VARS and $HTTP_POST_FILES instead of $_POST and $_FILES respectively

loz
0
 
LVL 1

Author Comment

by:kbach
ID: 9806476
Thanks loz, you're right.  However, I also found HeadAcheMike's article helpful with a related problem that 4.0.6 was causing.  Would you guys object to 150 for loz and 50 for HeadAcheMike?

Thanks again to both of you.

Scott.
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9806551
go for it, it's your choice

loz
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question