i am working on a project in php and trying to upload an excel file to server but it fails every time. My code files are below: all functions modules are working correctly in newupload.php file given below, but move_uploaded_file function is not working and file is not moving to destination. Please check my code and help please
//this is first page
//index.php
<!DOCTYPE html>
<html>
<body>
<form action="newupload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
//second page
//newupload.php
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);//destination
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);//returns extension of file
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = filesize($_FILES["fileToUpload"]["tmp_name"]);
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
//checks whether file is excel or not
if($FileType != "xlsx" ) {
echo "Sorry, Excel files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";// this error arising in my program
}
}
?>
//please help me, Thanks in advance
You can use PHPeXCEL Class http://blog.mayflower.de/561-Import-and-export-data-using-PHPExcel.html
The code is