Hi,
I am using following code to upload and save file to server in php. But file is not uploading.. there is no error in my code.. kindly guide me where i m wrong???
<?php
$allowedExts ="ppt";
$extension = end(explode(".", $_FILES["file"]["name"]));
if (in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"myphp/MyPP/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
.....
html code
<html>
<head>
</head>
<body>
<form method="post" enctype="multipart/form-data">
Select Presentation
<input type="hidden" name="upload" value="1" />
<input type ="file" id="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>
//*********************
// output
//*********************
when i load the php page... following messages are displayed...
( ! ) Notice: Undefined index: file in C:\wamp\www\fileUpload.php on line 9
Call Stack
# Time Memory Function Location
1 0.0005 375624 {main}( ) ..\fileUpload.php: 0
( ! ) Warning: in_array() expects parameter 2 to be array, string given in C:\wamp\www\fileUpload.php on line 11
Call Stack
# Time Memory Function Location
1 0.0005 375624 {main}( ) ..\fileUpload.php: 0
2 0.0006 376008 in_array ( ) ..\fileUpload.php:11
Invalid file
and on upload event this behavior does not change....