Hi this is scorpionz
I am uploading an excel sheet file using PHP
Now the file code is working fine for gif files but not working if i provive xls extension
Here is the php main code
<?php
// include 'config.php'
include 'uploadcode.php';
if(isset($_POST['upload_file']))
{
$user_file = $_FILES["car_info_file"]["name"];
upload_files($_FILES["car_info_file"]["name"]);
}
?>
<body>
<form name="uploadfile" action="" method="post" enctype="multipart/form-data">
<div class="upload-box">
<div style='border-left-width:0px;border-right-width:0px;border-top-width:0px;border-bottom-width:1px;border-color:#C0C0C0;border-style: solid; background-color:#669900;text-align:center; width:'>
<a href="#">Upload File </a></div>
</div>
<div>
<table class="bodyBg" bgcolor="#333333">
<tr>
<td width="94" align><span class="style1">Upload Your Display </span></td>
<td width="246"><input type="file" name="car_info_file" id="car_info_file" style="height: 19px; width:100px; font-size:87%;"/></td>
</tr>
<tr>
<td colspan="2" align><input type="submit" name="upload_file" value="Upload" /></td>
</tr>
</table>
</div>
</div>
</form>
</body>
The above is the main file and in PHP block i am calling a PHP function with name upload_files.... and below is that php function code
function upload_files($fil)
{
if((!empty($_FILES["car_info_file"])) && ($_FILES['car_info_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_FILES['car_info_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
//echo $ext;
if (($ext == "xls") && ($_FILES["car_info_file"]["type"] == "text/xls" ) && ($_FILES["car_info_file"]["size"] < 2000000)) {
//Determine the path to which we want to save this file
// $newname = 'C:\xampp\htdocs\online_shopping\uploaded_images\$filename';
$newname = 'C:\xampp\htdocs\hblcars\file_folder\\'.$filename;
// echo $newname;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['car_info_file']['tmp_name'],$newname))) {
// echo "It's done! The file has been saved and Uploaded as: ".$newname;
echo "<div style='background-color:#C0C0C0;color:#0099CC;font-weight:bold;text-align:center;'>It's done! The file has been saved and Uploaded</div>";
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["car_info_file"]["name"]." already exists";
}
} else {
echo "Error: Only .XLS files under 200000Kb are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
}
I think the Problem is here
if (($ext == "xls") && ($_FILES["car_info_file"]["type"] == "text/xls" ) && ($_FILES["car_info_file"]["size"] < 2000000))
because i am getting this error: Error: Only .XLS files under 200000Kb are accepted for upload
Thanks and Regards
Scorpionz