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
Solved

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

Posted on 2003-11-22
6
472 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

790 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