• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

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

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
kbach
Asked:
kbach
  • 2
  • 2
  • 2
1 Solution
 
HeadAcheMikeCommented:
$test = $_POST['test'];

should work fine presuming that the forms method is POST
0
 
kbachAuthor Commented:
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
 
HeadAcheMikeCommented:
>> 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
lozlozCommented:
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
 
kbachAuthor Commented:
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
 
lozlozCommented:
go for it, it's your choice

loz
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now