Click here to Skip to main content
16,019,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<html>
<head> <title> </title></head>
<body> 
<form enctype="multipart/form-data" name="upload" action="upload.php" method="post">
<input  name="file4upload"  type="file"> </input> <br>
<input name="submit" type="button" value="Upload File" > 
</form>
</body>



</html>






PHP
$$target_path="upload/";
$target_path=$target_path.basename($_FILES['file4upload']['name']);
if(move_uploaded_file($_FILES['file4upload']['tmp_name'],$target_path))
{
echo " File ".basename($_FILES['file4upload']['name'])."has been uploaded";
}


else
{
echo "Unsuccessful";
}





Error i get is

Notice: Undefined index: file4upload in C:\Documents and Settings\All Users\Documents\PHP practice\upload.php on line 3

Notice: Undefined index: file4upload in C:\Documents and Settings\All Users\Documents\PHP practice\upload.php on line 4
Unsuccessful 


php version :5.1
IIs 5.1
OS win xpsp3



kindly help me... and where i go wrong.
Thanx...
Posted
Updated 8-Aug-12 19:04pm
v2
Comments
[no name] 12-Jul-12 15:11pm    
Where are "'tmp_name'" and "'name'" defined?
Peter_in_2780 12-Jul-12 18:40pm    
by PHP. See the PHP manual under POST method uploads.
Sandeep Mewara 12-Jul-12 15:14pm    
What is 'name'? 'tmp_name'?
Peter_in_2780 12-Jul-12 18:41pm    
defined by PHP. See the PHP manual under POST method uploads.
Sandeep Mewara 13-Jul-12 2:05am    
Thanks for sharing the info. Yes, I didnt knew hence I asked. Would have posted it as an answer if I was so sure.

:)

Are you using the form and action on the same page?

If yes change that to a different page. It will solve your problem.
 
Share this answer
 
it's working fine after changing a little
HTML
<html>
<head> <title> </title></head>
<body> 
<form enctype="multipart/form-data" name="upload" action="upload.php" method="post">
<input name="file4upload" type="file"> </input> <br>
// change here at input type
<input name="submit" type="submit" value="Upload File"> 
</input></br></form>
</body> 
</html>


upload.php code:
PHP
$target="upload/";
$target_path=$target.basename($_FILES['file4upload']['name']);
if(move_uploaded_file($_FILES['file4upload']['tmp_name'],$target_path))
{
echo " File ".basename($_FILES['file4upload']['name'])."has been uploaded";
}
 

else
{
echo "Unsuccessful";
}
?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900