File upload problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barnes529
Forum Newbie
Posts: 17
Joined: Thu Apr 19, 2007 4:18 am

File upload problem

Post by barnes529 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


fileupload.html
[syntax="html"]<html>
 <body>
 <form name="frmname"action="upload.php" method="post">
 upload your file:<input type="file" name="file"><br>
 <input type="submit" name="submit" value="submit">
</form>
</body>
</html>

upload.php[/syntax]

Code: Select all

<?php
   if ($_FILES["file"]["error"] > 0)
   {
    echo "Error:". $_FILES["file"]["error"] ."<br>";
   }
else
 {
  echo "upload:". $_FILES["file"]["name"] ."<br>";
  echo "type:". $_FILES["file"]["type"] ."<br>";
  echo "size:". ($_FILES["file"]["size"]/1024) ."kb<br>";
  echo "stored in:". $_FILES["file"]["tmp_name"] ."<br>";
} 
?>
when i uploading some text file and click submit button the following o/p is showing:
Notice: Undefined index: file in c:\easyphp1-8\www\upload.php on line 2

Notice: Undefined index: file in c:\easyphp1-8\www\upload.php on line 8
upload:

Notice: Undefined index: file in c:\easyphp1-8\www\upload.php on line 9
type:

Notice: Undefined index: file in c:\easyphp1-8\www\upload.php on line 10
size:0kb

Notice: Undefined index: file in c:\easyphp1-8\www\upload.php on line 11
stored in:
how to reslove this problem..thanks in advance..


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
bert4
Forum Newbie
Posts: 18
Joined: Wed Apr 18, 2007 9:44 am
Location: Bali, Indonesia

Post by bert4 »

Try this:

(look at enctype)

Code: Select all

<html>
<body>
<form name="frmname" enctype="multipart/form-data" action="upload.php" method="post">
upload your file:<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
barnes529
Forum Newbie
Posts: 17
Joined: Thu Apr 19, 2007 4:18 am

Post by barnes529 »

ok may thanks.i forgot about enctype="multipart/form-data" in form tag
Post Reply