Solved

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

Posted on 2003-11-22
6
478 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

749 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