Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Why does not $HTTP_POST_FILES works withing function...

General discussions related to php

Moderators: macek, egami, gesf

Why does not $HTTP_POST_FILES works withing function...

Postby Mazerman » Sat Jul 19, 2003 12:30 am

Hi!

I wonder why $HTTP_POST_FILES doesn't work within functions and classes in PHP.

I've got this code:

file 1: test.php (simple form)
--------------
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" ENCTYPE="multipart/form-data" action="test2.php" method="post"><table width="500" border="1" cellspacing="5">
  <tr>
    <td><input name="user_file" type="file" size="50"></td>
  </tr>
  <tr>
    <td><input name="submit" type="submit" value="send"></td>
  </tr>
</table>
</form>
</body>
</html>


file 2: test2.php (handles form)
---------------
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
   function shoot()
   {
      if (isset($HTTP_POST_FILES['user_file']))
         echo "hello";
   }
?>
<body>
<?php
   shoot();   // this wont work
   
   // this will work
   //if (isset($HTTP_POST_FILES['user_file']))
   //      echo "hello";   
?>
</body>
</html>


Would be thankful if someone can help me out...!!!
Mazerman
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jan 26, 2003 2:57 pm
Location: Sweden

Postby pootergeist » Sat Jul 19, 2003 1:39 am

you'd need to globalise the _FILES array within the function

function shoot()
{
global $HTTP_POST_FILES;
echo $HTTP_POST_FILES['user_file']['tmp_name'];
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK


Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron