I have written a php code for uploading a file,but it seems there is some issue with the code.can anyone plz help me out in resolving the issue. The HTML code is:
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="C:\xampp\htdocs\upload.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
And the PHP code is as follows:
<?php
if( $_FILES['file']['name'] != "" )
{
copy( $_FILES['file']['name'], "C:/xampp/htdocs" ) or
die( "Could not copy file!");
}
else
{
die("No file specified!");
}
?>
<html>
<head>
<title>Uploading Complete</title>
</head>
<body>
<h2>Uploaded File Info:</h2>
<ul>
<li>Sent file: <?php echo $_FILES['file']['name'] ; ?>
<li>File size: <?php echo $_FILES['file']['size']/1024; ?>
<li>File type: <?php echo $_FILES['file']['type']; ?>
<?php $_FILES['file']['tmp_name']; ?>
</ul>
</body>
</html>
I am using xampp to run the PHP scripts.
**Onclicking
upload file button nothing is displayed as expected.**
So what is the output? Also, do print_r($_FILES)
to show how it is prepared for you to access, you are likely to be accessing the filename inaccurately.
Use the proper function and the correct array element:
move_uploaded_file($_FILES['file']['tmp_name'], '...');